使用 Git,是否可以重新应用祖先修订版?

发布于 2024-09-10 20:47:05 字数 266 浏览 7 评论 0原文

假设我有很久以前的修订版 A,并且做了一个令人满意的更改。

然后,后来,我有了修订版 B,它对很多文件进行了很多更改,包括清除更改 A。

现在,很久以后,我想重新应用修订版 A。有没有好的方法可以做到这一点?合并和樱桃选择命令似乎跳过了祖先的修订,并且我没有看到任何忽略祖先的标志。

总是有 diff/apply,但这些真的是最好的方法吗?看起来这可能是“有损的”(通过中间补丁格式)并且可能不允许 git 使用通常可以使用的所有工具......但这是我的不知情的预感。

Say I have revision A that's from a long time ago and made a desirable change.

Then, later on, I had revision B which made lots of changes to lots of files, including wiping out change A.

Now, much later, I want to re-apply revision A. Is there a good way to do this? The merge and cherry-pick commands seem to skip revisions that are ancestors, and I don't see any flags to ignore ancestry.

There's always diff/apply, but are those really the best way? It seems like this could be "lossy" (going through the intermediary patch format) and might not allow git to use all of the tools normally at its disposal... but this is an uninformed hunch on my part.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剪不断理还乱 2024-09-17 20:47:05

gitcherry-pickA 将完全按照您的要求进行操作。它不考虑祖先 - 它只查看已经应用了哪些更改。

这是一个例子:

git cherry-pick A
git cherry-pick A
git cherry-pick A

只会创建一个新的提交(最多)。第二个和第三个命令是无操作的,因为 A 的更改已经应用。但是,

git cherry-pick A
git cherry-pick B
git cherry-pick A
git cherry-pick B

将创建四个新提交。第一次和第三次提交都将执行相同的操作,而第二次和第四次提交将恢复第一次和第三次提交(即使提交 B 做了其他更改而不是恢复 A。)换句话说,这与

git cherry-pick A
git revert --no-edit HEAD
git revert --no-edit HEAD
git revert --no-edit HEAD

希望这有帮助是一样的。

git cherry-pick A will do exactly what you want. It does not look at ancestry - it only looks to see what changes have already been applied.

Here's an example:

git cherry-pick A
git cherry-pick A
git cherry-pick A

will only create one new commit (at most). The second and third commands are no-ops, since the changes of A have already been applied. However,

git cherry-pick A
git cherry-pick B
git cherry-pick A
git cherry-pick B

will create four new commits. The first and third commits will both do the same thing, while the second and fourth will revert the first and third (even if commit B made other changes than reverting A.) In other words, this is the same as

git cherry-pick A
git revert --no-edit HEAD
git revert --no-edit HEAD
git revert --no-edit HEAD

Hope this helps.

十二 2024-09-17 20:47:05

您可以使用 git checkout $REVISION 切换回您的修订(提交)。然后你应该从那里创建一个新分支。

git.cmd branch YOURCOMMIT

您可以使用镐来获取新分支所需的提交。

You can use git checkout $REVISION to switch back to your Revision (Commit). Then you should create a new branch from there.

git.cmd branch YOURCOMMIT

You can use pickaxe to get the commits you need for your new branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文