git-checkout

how can git checkout HEAD~2 go 10 commits back

懵懂的女人 提交于 2019-12-04 02:35:15
问题 There's a remote branch my-issue-branch and a local branch of the same name. We performed git pull --rebase to get the latest commits locally, but the two last commits are breaking the build. We want to go 2 commits back to build the project and do git checkout HEAD~2 which takes us about 10 commits back, instead of just two. Only git checkout <commit-hash> helps the situation. Keeping in mind, that four people work on this branch, what can be wrong? 回答1: Here's a simplified diagram: ...--o--

Restore deleted file not staged in git

萝らか妹 提交于 2019-12-04 00:23:18
问题 I accidentally removed the entire directory of my source code...with a nice rm -r. I know, really bad; but fortunately, I had a git repo in the containing directory. Thus, git has a huge list of unstaged changes of deleted files. For example: "deleted: src/caronmonitor/server.py" How do I get these files back? There is advice all over the web to do: git checkout file or git revert <commit> But as I understand that will restore the file to it's state at the last commit. I don't want to go back

--dry-run option in git checkout

心已入冬 提交于 2019-12-03 23:34:46
I use git checkout --<dir_name(or)file_name> to discard all my changes in the specific directory or in the file. Whenever I do that, GIT checks-out the directory (or) file from the repository. Is there a way I can tell GIT?, " do not override the changes, just tell me what would happen. " Similar to git clean -n (or) git clean --dry-run . UPDATE: Before I execute, git checkout --src/ , I would like to see what are the files would be overridden. I know we can use git status src/ . But, wouldn't it be great to have git checkout -n --src/ ? Not much command changes for the user. You can run $ git

Why is the git command to switch branches named “git checkout”?

邮差的信 提交于 2019-12-03 22:41:31
Why is the git command to switch branches named git checkout ? Does it really make sense ? I would name it git switch instead. Besides, git checkout has other meanings: e.g. reverting a file (like svn revert ) Mark Longair I see that most other answers are explaining what git checkout does and why "checkout" might be a reasonable way to describe that. However, while I love git dearly, this does touch on two serious points of frustration that arise when I'm trying to help people to understand the system: git checkout does two very distinct things, and it would be helpful for newcomers if they

How to pull into not-the-current-branch?

蹲街弑〆低调 提交于 2019-12-03 22:04:17
Say my current branch is myfeature. I want to get master up to date. Both git merge git pull always merge into the current branch, as far as I can tell. Is there a way to merge changes from a remote branch (eg, origin/master) into a branch I'm not currently on (master)? I can think of one way: git stash git checkout master git pull origin/master git checkout myfeature git stash apply Is there a better one? (It's possibly my whole question is wrong: would git fetch automatically update master to match origin/master, if remote-tracking is enabled?) You are correct that pull/merge only merges

Are there different meanings to the concept of 'tracking' in git?

ぐ巨炮叔叔 提交于 2019-12-03 17:28:47
问题 I run 'git branch -r' and get origin/branch1 origin/branch2 From the man page, the -r option will "list or delete (if used with -d) the remote-tracking branches". So origin/branch1 and origin/branch2 are known as remote-tracking branches. However, you can't commit directly onto a remote-tracking branch (an anonymous branch will be created instead). A remote-tracking branch simply tracks a remote branch when running 'git fetch'. Here's where the semantics get a little blurry for me. If I then

Get snapshot of a git repo on a particular date

霸气de小男生 提交于 2019-12-03 14:31:34
Say I have a repo with multiple banches. Is it possible to get the repo snapshot of some particular date/time using usual git foo? (We currently have code dumps every day, and I am thinking of ways to remove that) (Assuming no branches are permanently deleted, and the git commit history hasn't been played with) Edit: Interim branch merges are possible. VonC Beware of the @{<date>} , based on the reflog (meaning, limited by default to 90 days). See " Specifying Revisions " in git rev-parse . " git checkout by date " suggests another method: git checkout `git rev-list -n 1 --before="2013-09-25 5

Fetch a single tag from remote repository

妖精的绣舞 提交于 2019-12-03 12:10:48
问题 This command fetches all tags: git fetch origin --tags This command fetches a specific tag: git fetch origin refs/tags/1.0.0 But that doesn't let me do: git checkout tags/2.3.18 How can I fetch a single tag and then perform a checkout? 回答1: git fetch origin refs/tags/1.0.0 This fails because it doesn't write a local reference: it obtains the remote's refs/tags/1.0.0 , and any tag object(s), commits, etc., required to go with it; it drops those into FETCH_HEAD (as all git fetch commands always

Git pushd & popd? I.e., checkout last state

为君一笑 提交于 2019-12-03 09:13:23
问题 I'm writing a Bash script, and I want to checkout a tag and then checkout back to where I started. I tried git co HEAD@{1} , but when starting at master, that takes me back to the commit SHA of master but with a detatched head. Is there something like pushd & popd for Git? 回答1: git checkout @{-1} which can be abbreviated to git checkout - . From the manpage: As a special case, the "@{-N}" syntax for the N-th last branch checks out the branch (instead of detaching). You may also specify -

git - getting ALL previous version of a specific file/folder

ぃ、小莉子 提交于 2019-12-03 08:48:33
问题 I want to retrieve all previous version of a specific file in a git repository. I see it is possible to get one specific version with the checkout command, but I want them all. And the git clone command with the depth option doesn't seem to allow me to clone subfolder ("not valid repository name"). Do you know if it is possible and how? Thank you 回答1: OP wanted to retrieve all versions, but the answers would not deliver. Especially if the file has hundreds of revisions (all suggestions are