Git move n向前承诺 [英] Git move n commits forward
问题描述
我正在一个存储库的提交C(我刚刚做了一个git checkout hash_of_C
).
I'm in commit C (I just did a git checkout hash_of_C
) of a repository.
A - B - C - ...<19>... - D - ...<many many commits> - Z
哪个Z是master分支中的最后一个提交
Which Z is the last commit in the master branch
现在,我想向前进行20次提交.
Now, I want to move forward 20 commits.
推荐答案
如果我正确理解,您想向前移动20个C提交,而Z是master分支上的最后一个提交,但不一定是从20个提交开始C.
If I am understanding correctly, you want to move forward 20 commits from C, and Z is the last commit on the master branch but not necessarily the 20th commit from C.
从C做
C > git checkout $(git rev-list --topo-order HEAD..master | tail -20 | head -1)
它将结帐20个向前的提交如果存在.
It will checkout the 20 commit forward if it exists.
我对此并不完全有信心,但这就是它的作用.
I am not totally confident about it but here is what it does.
git rev-list --topo-order HEAD..master 将为您提供从C到master的所有提交列表/每行一个.
git rev-list --topo-order HEAD..master will give you list of all the commits from C to master/one per line.
> ➦ b17c0a7 > git rev-list --topo-order HEAD..master
3c5b47003a5bc576d6c5d13b065bb70aef28828f
306fee6443d0e2ebb0a5372dfdff0d55728950f3
02acfd4b6987dfc8bc689a18d21ee82ad8132839
当我们做尾巴-20时,我们基本上想从底部20行开始从列表中切出一块.如果我们以-1开头,我们将进一步削减列表,仅获取最高的项目.这样,我们从当前提交中获取第20个项目.
When we do tail -20 we basically want to cut a piece out of this list from bottom 20 line up. If we do head -1, we cut the list further, taking only the top item. This way we get the 20th item forward from the current commit.
哪个是 $(git rev-list --topo-order HEAD..master | tail -20 | head -1)
这篇关于Git move n向前承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!