Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 在同一分支上的提交历史记录中移动提交的最简单方法_Git_Github - Fatal编程技术网

Git 在同一分支上的提交历史记录中移动提交的最简单方法

Git 在同一分支上的提交历史记录中移动提交的最简单方法,git,github,Git,Github,我希望能够轻松地从我的提交历史记录中的任何地方进行提交,并使它们成为同一分支上最近的提交。我更愿意使用git命令行工具来实现这一点,但我也对GUI工具持开放态度 我调查了git cherry pick,但根据我对文档的理解和我自己的测试,cherry pick一个现有的提交会使cherry pick(最近的)提交变为空,因为它已经存在于历史记录中 您可以假设不会有冲突,因为我的需求来自于遵循中概述的开发策略。即使有,我也可以根据需要纠正它们 编辑:我找到了一个使用交互式重定基址的解决方案。我把它

我希望能够轻松地从我的提交历史记录中的任何地方进行提交,并使它们成为同一分支上最近的提交。我更愿意使用git命令行工具来实现这一点,但我也对GUI工具持开放态度

我调查了git cherry pick,但根据我对文档的理解和我自己的测试,cherry pick一个现有的提交会使cherry pick(最近的)提交变为空,因为它已经存在于历史记录中

您可以假设不会有冲突,因为我的需求来自于遵循中概述的开发策略。即使有,我也可以根据需要纠正它们


编辑:我找到了一个使用交互式重定基址的解决方案。我把它作为这个问题的答案发布了出来,但我很想知道还有什么其他解决方案。

git-rebase-I HEAD~numberofcommissions
其中
numberofcommittes
是要检查的提交量

Git将打开带有提交列表的编辑器,您可以在其中选择编辑、挤压或跳过任何提交。如果要删除提交,请删除该行:

# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
#
# These lines can be re-ordered; they are executed from top to bottom.
#    
# If you remove a line here THAT COMMIT WILL BE LOST.
请注意,执行此操作时,您的分支将与远程分支不同,因此您必须强制推送,如果其他任何人有旧历史记录的副本,则必须硬重置到新历史记录


请阅读分章。它得到了比我能提供的更好的解释。

我发现的一个相当简单的解决方案是使用的交互式重基模式来重新排序提交。调用
git-rebase-i HEAD~3
对HEAD之前的三个最新提交进行重新设置时,会出现以下情况(我自己的注释用
#
注释):

通过将commit I want的行移到该列表的底部,它将在重新基址结束时重新排序为历史上最新的一行:

pick 9390105 [bug 972919] Cleaned up app.js
pick 626e865 [bug 972919] Removed CORS logic
pick 57c3e7e [bug 972919] Removed outdated information from the readme # <-- this one will be most recent
pick 9390105[bug 972919]清理app.js
拾取626e865[bug 972919]已删除CORS逻辑

pick 57c3e7e[bug 972919]从自述中删除了过时的信息#感谢您的回复。作为一个nit,rebase的交互模式没有
skip
命令-必须删除表示提交的行才能完成您的建议。
pick 9390105 [bug 972919] Cleaned up app.js
pick 626e865 [bug 972919] Removed CORS logic
pick 57c3e7e [bug 972919] Removed outdated information from the readme # <-- this one will be most recent