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--*-----o------o--o   <-- you are here
         \          /
          o--o--o--o

You are at the marked commit, towards the right. You need to walk to the * commit towards the left, following one or the other lines, or maybe even following both at the same time. How many os will you traverse? How many os are there "between" commit * and the right hand edge one?

Now consider what happens with Git when there are merge commits (you must have some near the tip of your current branch, to be seeing this). The ~2 count walks back two commits on some particular line. What about all the commits on the other lines? What happens to them?



来源:https://stackoverflow.com/questions/45574086/how-can-git-checkout-head2-go-10-commits-back

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!