重新应用来自同一分支的先前提交的更改,类似于合并/变基。

huangapple go评论53阅读模式
英文:

git - re-apply changes from a previous commit from same branch like a merge/rebase

问题

在同一个分支上,你想要重新应用在提交 B 中对 foo.cpp 所做的更改,并手动解决冲突,就好像它是一个合并或变基操作。请注意,提交 B 已经在历史记录中,所以你尝试使用 mergerebasecherry-pick 失败了,因此提出了这个问题。

如何完成这个操作?

英文:

Say I have a file foo.cpp tracked by git, which was added in commit A. Then in commit B, I have added a big set of changes.

Now later, on the same branch, I have made changes to foo.cpp again, however it was based on the version of foo.cpp as it was in commit A. I would now like to re-apply the changes to it I made it commit B, and resolve the arising conflicts manually as if it were a merge or a rebase. Note that commit B is already in the history, so my attempts to use merge, rebase, or cherry-pick have failed, hence this question.

How can this be done?

答案1

得分: 2

添加并提交您现在拥有的内容。将其命名为C。现在仅对文件foo.cpp比较A和B,将该差异导入文件。然后使用git apply应用该文件。

英文:

Add and commit what you have now. Call it C. Now diff A to B for just the file foo.cpp and pipe that diff into a file. Now git apply that file.

huangapple
  • 本文由 发表于 2023年6月18日 20:46:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定