git-checkout

git checkout <commit-hash> vs git checkout branch

泪湿孤枕 提交于 2019-12-01 00:55:41
问题 I was playing around with git and got confused here. The HEAD of develop branch is at 235a6d8 When I do: git checkout 235a6d8 from any other branch or from develop branch , this leaves me in detached head. I am not sure why does this happen when I am checking out to the latest commit on this branch. When I do: git checkout develop I can switch to develop branch correctly. I am not getting the difference between git checkout <commit-has> and git checkout branchname . How they are different ?

GIT multiple local checkouts

谁说我不能喝 提交于 2019-11-30 22:30:38
I want to checkout multiple branches of the same git repostiory on the same Computer (Linux and Windows). However as the repository might be huge, I would prefer to have the repository once and only multiple working directories. Is this possible? How so? VonC It is possible since Git 2.5 and its git worktree command. It replaces an older script contrib/workdir/git-new-workdir , with a more robust mechanism where those "linked" working trees are actually recorded in the main repo new $GIT_DIR/worktrees folder (so that work on any OS, including Windows). Once you have cloned a repo (in a folder

GIT multiple local checkouts

走远了吗. 提交于 2019-11-30 17:54:59
问题 I want to checkout multiple branches of the same git repostiory on the same Computer (Linux and Windows). However as the repository might be huge, I would prefer to have the repository once and only multiple working directories. Is this possible? How so? 回答1: It is possible since Git 2.5 and its git worktree command. It replaces an older script contrib/workdir/git-new-workdir , with a more robust mechanism where those "linked" working trees are actually recorded in the main repo new $GIT_DIR

Get git current branch/tag name

限于喜欢 提交于 2019-11-30 13:10:27
问题 How can I get the current branch or tag name for my working copy? I have seen references that indicate rev-parse --abbrev-ref HEAD will give branch name, but this doesn't work if the checkout is of a tag, in which case it just returns 'HEAD'. I need to somehow get the tag name of these revisions. To be clear, I want one of two possible names: If the current checkout is the HEAD of a branch, I want the branch name If it is a detached HEAD, I want the tag name (on the assumption there is a tag)

smartgit delete commit and return to previous commit

99封情书 提交于 2019-11-30 13:02:59
By mistake i have made a commit that now i want to delete from the history log and return to a previous commit. I have been trying to checkout the commit that i want to return to but Smartgit ask me to create a local branch in order to do this (screen shot attached) and since im not an expert with SG i really need some advice. I have also try to revert the commit that i made by mistake but i still see the commit on the log. This is how the log look now: When trying to checkout : How my log looks at the moment : What i want to do is delete the first two commits from the log and return to the

What is the difference between “git checkout — .” and “git reset HEAD --hard”?

匆匆过客 提交于 2019-11-30 12:21:11
问题 This is not a general question about what '--' does, as in the marked duplicate. This is a git-specific question asking for clarity on what the operational differences are between the mentioned commands. If I want to clean out my current directory without stashing or committing, I usually use these commands: git reset HEAD --hard git clean -fd A co-worker also mentioned using this command: git checkout -- . It's a difficult command to google, and it's not clear to me from the git

GIT: commit changes to old/safe branch while in new/dirty/dev branch without checking out or losing unstaged data

有些话、适合烂在心里 提交于 2019-11-30 12:12:40
I created a new Branch before I started dev on something experimental. I usually forget that (which isn't a problem), but now I did it beforehand. Since then I have updated 3 files. In 2 are only experimental changes that I DON'T want committed to the safe branch. In 1 are only safe (minor) changes that I definitely DO want committed to the safe branch. I'm fine with these last changes to be committed to the new branch as well (but rather not). Is it possible - I'm sure it is - to (quickly) commit a few unstaged, uncommitted changes from my (dirty) working dir to an old, safe branch? The only

Get git current branch/tag name

别来无恙 提交于 2019-11-30 11:02:49
How can I get the current branch or tag name for my working copy? I have seen references that indicate rev-parse --abbrev-ref HEAD will give branch name, but this doesn't work if the checkout is of a tag, in which case it just returns 'HEAD'. I need to somehow get the tag name of these revisions. To be clear, I want one of two possible names: If the current checkout is the HEAD of a branch, I want the branch name If it is a detached HEAD, I want the tag name (on the assumption there is a tag) I think you want this: git symbolic-ref -q --short HEAD || git describe --tags --exact-match That will

dot sign's meaning in git checkout command

折月煮酒 提交于 2019-11-30 09:43:27
if I use git command like this: git checkout -- . I know its effect is to discard all unstaged files everywhere. Can anyone tell me what is the meaning of the dot sign (.) in this command? The dot stands for the current directory. The command you've mentioned means: Do a git checkout of the current directory (recursively). The double-dashes separate options from filespecs (like . ). The dot ( . ) refers to the current working directory. You are asking git to checkout the current directory from the checked out branch . The double-dash is used to separate references, such as master or HEAD from

Why doesn't setting GIT_WORK_TREE work in a post-commit hook?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 09:36:32
I'm trying to use the following post-commit hook to deploy to a particular directory after each successful commit: #!/bin/sh export GIT_WORK_TREE=/var/www/example/ export GIT_DIR=/home/mark/test/.git/ git checkout -f However, after committing I get the following error: $ git commit -m 'An example commit.' fatal: Unable to create '/var/www/example/.git/index.lock': No such file or directory [master 0938e48] An example commit. ... as if the GIT_WORK_TREE setting is being ignored. Why does setting this environment variable appear to be not working? I'm using git version 1.7.4.1. The problem here