![](/img/trans.png)
[英]How to overwrite over all commits after a specific commit without having to 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-commit
, my-commit
, original-commit-1
和original-commit-2
的commit-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.