我如何将最后的N承诺集成到一个承诺中?
当前回答
最方便的方式是使用 GitHub 桌面. 只需在历史中选择所有命令,右键单击并选择“Squash x 命令”:
此分類上一篇
其他回答
使用 git rebase -i <after-this-commit> 并在第二次和随后的命令中取代“squash”或“fixup”,如手册中所描述。
在此例子中, <after-this-commit> 是 SHA1 hash 或当前分支的 HEAD 的相对位置,从该分支的 Commits 被分析为 rebase 命令. 例如,如果用户希望从当前 HEAD 查看 5 个 Commits 在过去的命令是 git rebase -i HEAD~5.
下面是另一个视觉例子,在执行后会发生什么: git rebase -i HEAD~3
此分類上一篇
來源: https://www.git-tower.com/learn/git/faq/git-squash/
您可以使用 git merge --squash 为此,这比 git rebase -i 略有优雅。
警告: 首先,请确保您完成工作 - 检查 git 状态是干净的(因为 git 重新设置 - 硬将抛弃错误和错误的变化)
然后:
# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
git commit
git merge 的文档详细描述了 --squash 选项。
更新:这个方法的唯一真正优点,比克里斯·约翰森(Chris Johnsen)在他的回答中提出的更简单的吉特重新设置 --soft HEAD~12 &&吉特承诺是,你会得到承诺的消息,以每一个承诺的消息,你正在破坏。
如果您不关心承诺信息的承诺之间,您可以使用
git reset --mixed <commit-hash-into-which-you-want-to-squash>
git commit -a --amend
在分支中,你想将承诺结合起来,运行:
git rebase -i HEAD~(n number of commits back to review)
例子:
git rebase -i HEAD~2
此将打开文本编辑器,您必须在每个承诺前更换“点击”,如果您希望这些承诺合并。
p, pick = 使用 commit
s, squash = 使用承诺,但输入前承诺
例如,如果您正在寻找将所有承诺合并到一个,则“选择”是您所做的第一个承诺,并且所有未来的承诺(位于第一个下方)都应该设置为“滑动”。如果使用vim,请使用 :x 在输入模式中保存和输出编辑器。
然后继续下调:
git add .
git rebase --continue
更多关于此和其他方式重新写下你的承诺历史,请参见这篇有用的文章
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别