Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.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 如何将已推送的提交从X挤压到Y?_Git_Github - Fatal编程技术网

Git 如何将已推送的提交从X挤压到Y?

Git 如何将已推送的提交从X挤压到Y?,git,github,Git,Github,我想挤压已经推送到远程存储库的从X到Y的提交(比如从第二次到最后一次提交到第五次到最后一次提交)。我在Stackoverflow上看到了挤压X上次提交的答案,但我对挤压最后X次提交不感兴趣,而是在最后几次提交之后进行提交。您需要的是一个“交互式重基”(git-rebase-I),您可以使用它将分支重基到自身。该命令将为您提供一个在您的范围内指定的提交列表,然后您可以要求编辑、挤在一起、单独留下——例如在提交范围的中间。 -我 --互动的 列出将要重定基础的提交。让用户在重定基址之前编辑该列表。

我想挤压已经推送到远程存储库的从X到Y的提交(比如从第二次到最后一次提交到第五次到最后一次提交)。我在Stackoverflow上看到了挤压X上次提交的答案,但我对挤压最后X次提交不感兴趣,而是在最后几次提交之后进行提交。

您需要的是一个“交互式重基”(
git-rebase-I
),您可以使用它将分支重基到自身。该命令将为您提供一个在您的范围内指定的提交列表,然后您可以要求编辑、挤在一起、单独留下——例如在提交范围的中间。

-我 --互动的 列出将要重定基础的提交。让用户在重定基址之前编辑该列表。此模式还可用于拆分提交(请参阅下面的拆分提交)

例如:

15:49 $ git log --oneline -5
ffdad47 2020-10-12 (HEAD -> master) fourth commit [Martin KJELDSEN]
60b7363 2020-10-06 third commit [Martin KJELDSEN]
a72eea4 2019-03-28 second commit [Martin KJELDSEN]
b9b64b8 2019-03-28 first commit [Martin KJELDSEN]
然后运行rebase命令将所有提交重新设置到
b9b64b8
上的基础

git rebase -i b9b64b8
Git在编辑器中向我展示了以下列表,我将选择挤压中间的一个提交(
fixup
=挤压并使用现有的提交消息。
squash
=让用户在继续重基之前将所有提交消息合并在一起)

选择a72eea4秒提交
修正60b7363第三次提交
选择第四个提交
#将b9b64b8..ffdad47重设到b9b64b8上(3个命令)
#                                                                                
#命令:
#p,pick=使用提交
#r,reword=使用提交,但编辑提交消息
#e,edit=使用提交,但停止修改
#s,squash=使用提交,但合并到以前的提交中
#f,fixup=类似于“squash”,但丢弃此提交的日志消息
#x,exec=使用shell运行命令(行的其余部分)
#b,break=stop here(稍后用'git rebase--continue'继续重新基址)
#d,drop=remove-commit
#l,label=用名称标记当前磁头
#t,重置=将磁头重置为标签
#m,合并[-C |-C][#]
# .       使用原始合并提交的
# .       消息(如果没有原始合并提交,则为单行)
#。已指定)。使用-c重写提交消息。
#                                                                                

保存此配置并继续使用重新基础时,您将根据
重新基础-i
配置重写历史记录

我发现使用反向提交工作流很容易。要执行该命令,我从最新的提交开始,我想退出并使用以下命令(或您最喜欢的GUI工具)沿着提交历史进行操作:

git revert[commit\u hash]


根据您管理提交消息的方式以及在提交索引中的位置,有一些有用的标志,如
--无编辑
--无提交

我发现错误:git:'ls'不是git命令。请参阅“git--help”。如何查看我的git历史记录?
ls
是我的自定义宏,对不起。我将用
git log
:)替换它。您推荐什么GUI工具?我使用SourceTree处理这个特定用例。GitHub也有一个不错的。命令行通常在绑定时最有效。不管出于什么原因,我似乎不能爱上IDE中的任何Git集成
pick a72eea4 second commit                                                              
fixup 60b7363 third commit
<There could be more commits here>
pick fourth commit
                                                                             
# Rebase b9b64b8..ffdad47 onto b9b64b8 (3 commands)                              
#                                                                                
# Commands:                                                                      
# p, pick <commit> = use commit                                                  
# r, reword <commit> = use commit, but edit the commit message                   
# e, edit <commit> = use commit, but stop for amending                           
# s, squash <commit> = use commit, but meld into previous commit                 
# f, fixup <commit> = like "squash", but discard this commit's log message       
# x, exec <command> = run command (the rest of the line) using shell             
# b, break = stop here (continue rebase later with 'git rebase --continue')      
# d, drop <commit> = remove commit                                               
# l, label <label> = label current HEAD with a name                              
# t, reset <label> = reset HEAD to a label                                       
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]                     
# .       create a merge commit using the original merge commit's                
# .       message (or the oneline, if no original merge commit was               
# .       specified). Use -c <commit> to reword the commit message.              
#