如何跳过 git 中的提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10128473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:45:53  来源:igfitidea点击:

How can I skip commits in git?

gitgit-commit

提问by vguzmanp

I have some commits that I don't want in my project, but there's a commit based on them which I do want in it. This is my GitHub "Network" graph of the repository (ASCII, as I still cannot post images):

我有一些我不想要的提交在我的项目中,但是有一个基于它们的提交,我确实想要它。这是我的存储库的 GitHub“网络”图(ASCII,因为我仍然无法发布图像):

[]--[]--[_]
|        |
|        ------->|
---------->[·]--[·]--[*]

(-> means a merge)

(-> 表示合并)

I want to delete the changes made in the two [·] commits, and base the [*] one on the [_] one above. I've tryed merging and rebasing, but they apply the changes of the unwanted commits. Is it possible?

我想删除在两个 [·] 提交中所做的更改,并将 [*] 一个基于上面的 [_] 一个。我尝试过合并和变基,但他们应用了不需要的提交的更改。是否可以?

Sorry if I'm not clear, English isn't my mother language. Thanks in advance.

对不起,如果我不清楚,英语不是我的母语。提前致谢。

回答by KurzedMetal

I can give you two options:

我可以给你两个选择:

  • Interactive rebase(git rebase -i) presents you a list of commits, editing this list will change the result of the operation; lets you reorder, delete or tag these commits for miscellaneous operations. In your case, you can rebase [*]'s branch into [_]'s and delete the lines unwanted commits.

  • Cherrypicklets you apply the changes of a single commitinto another branch. In your case, you can simply cherrypick commit [*]into [_]'s branch.

  • 交互式变基( git rebase -i) 为您呈现一个提交列表,编辑此列表将更改操作的结果;允许您为杂项操作重新排序、删除或标记这些提交。在您的情况下,您可以将[*]'s 分支变基为[_]'s 并删除不需要的提交行。

  • Cherrypick允许您将单个提交的更改应用到另一个分支。在你的情况下,你可以简单地cherrypick commit [*]into[_]的分支。

回答by vhallac

You could check out your _and cherry pickthe *. If you want that on a separate branch, you can branch off from _before doing this.

你可以检查你的_樱桃挑选*。如果你想在一个单独的分支上,你可以_在这样做之前分支。

回答by Yogesh

You can combine your commits by rebase and squashing the ones you dont need. May be you did not do squash and pick.

您可以通过变基和压缩不需要的提交来组合您的提交。可能是你没有做壁球和采摘。

Refere this: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

参考这个:http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html