我如何将最后的N承诺集成到一个承诺中?
当前回答
您可以使用 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 &&吉特承诺是,你会得到承诺的消息,以每一个承诺的消息,你正在破坏。
其他回答
有人提到在 IntelliJ IDEA UI 上做得多容易:
转到 git 窗口 手动选择所有要融入一个的承诺. 右键单击 > Squash 承诺 > 编辑失败的承诺消息 点击左侧的分支名称 > 右键单击 > Push > Force Push
此分類上一篇
要将最后10个承诺分为1个单一承诺:
git reset --soft HEAD~10 && git commit -m "squashed commit"
如果你也想更新远程分支与破碎的承诺:
git push -f
git rebase -i HEAD^^
在哪里 ^'s 的数量是 X
(此分類上一篇: 最後兩個命令)
方法1 如果你有很多承诺
git rebase -i master 然后按一下键盘“i”来编辑
你会看到这样的:
pick etc1
pick etc2
pick etc2
用“f”取代“ pick”这个词,然后按 esc y :wq。
pick etc1 //this commit will the one commit
f etc2
f etc2
按下这个命令
git push origin +head
方法2 如果你有少数承诺,你可以这样做去删除承诺,你必须这样做去删除你的第二承诺等等。
git reset --soft HEAD^1 // or git reset --soft head~1
git commit --amend //then press `:wq`
git push -f
方法 3 如果你已经有一个承诺,你不想提交另一个承诺更多
git add files...
git commit --amend //then press `:wq`
git push origin +head
我认为最简单的方式来做到这一点是通过创建一个基于大师的新分支,并进行功能分支的合并。
git checkout master
git checkout -b feature_branch_squashed
git merge --squash feature_branch
然后,你有所有的变化准备好进行。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别