繁体   English   中英

在git pull中的所有提交之后,如何将本地提交移动到?

[英]How can I move a local commit to after all commits in a git pull?

这是我的情况。 我一直在开发功能并进行本地提交。 我继续工作。 同时,一位同事推动了我需要的更改。 其中一些更改位于我正在处理的相同文件中。

我目前有一些代码,在从源头提取之前需要存放。
有没有一种方法可以提取代码,以便同事代码在提交历史记录中的最后一次本地提交之前就存在?
我知道,我的本地提交比我要提交的提交更早。
我将得到这样的结果:

older commits -> my commit -> origin commit 1 -> origin commit 2 -> popped stash

但是我想要的是:

older commits -> origin commit 1 -> origin commit 2 -> my commit -> popped stash

我能看到的唯一方法是撤消本地提交,将全部存储,然后拉然后弹出存储。 有什么办法可以保持我的旧提交?

我刚刚看到这里有git-rewrite-history的标签,所以可能吗?

撤消和重新应用一系列提交称为rebase 拉的变化和rebase ,而不是merge它们,你可以使用--rebase选项:

git stash
git pull --rebase origin master
git stash pop

您可以使用git cherry-pick概念:

首先从git log输出中复制commit-hash-before-my-commitmy-commitoriginal-commit-1original-commit-2commit-hash-before-my-commit

$ git log                 # First copy the commit hashes

$ git checkout -b b1      # create a new branch b1 (just for experiment)

$ git reset --hard <commit-hash-before-my-commit>

$ git cherry-pick <original-commit-1>
$ git cherry-pick <original-commit-2>
$ git cherry-pick <my-commit>
$ git stash pop

现在, git log应该显示您想要的提交历史。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM