git checkout HEAD〜2怎么办10提交回来 [英] how can git checkout HEAD~2 go 10 commits back

查看:112
本文介绍了git checkout HEAD〜2怎么办10提交回来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个远程分支 my-issue-branch 和一个同名的本地分支。我们执行了

git pull --rebase



在本地获得最新的提交,但最后两个提交正在破坏构建。我们想要返回2个提交来构建项目并执行
$ b $ git checkout HEAD〜2



这需要我们提交大约10次提交,而不是仅提交两次。





git checkout< commit-hash>



有助于这种情况。 b
$ b

请记住,这四个人在这个分支上工作,有什么可能是错的?

解决方案

<下面是一个简化图:

  ...-- o  -  * ----- o ---- --o  -  o<  - 您在这里
\ /
o - o - o - o

您处于明显的承诺中,向右转。您需要走到左边的 * 提交,跟随一条或其他线路,或者甚至可以同时跟随两条线路。你会遍历多少个 o s? commit * 和右边缘之间有多少 o s?



现在考虑一下在合并提交时发生了什么(你必须在你当前分支的顶端附近有一些东西来看这个)。 〜2 count在某些特定行上回退两个提交 。那么其他行上的所有提交呢?他们会怎么样?


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?

解决方案

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?

这篇关于git checkout HEAD〜2怎么办10提交回来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆