Github PR 时合并多次提交的 git commits All In One
git commit -s
GitHub 会帮你把新增的 commits 全部追加到一个未合并 PR 里去(PR 会自动更新)
git add <files>
git commit -s -m "some description here"
# s, squash <commit> = use commit, but meld into previous commit
-s === --squash
git push origin feat-xxx
PR 前合并多个 Commits, 方便 code review ✅
# 通过 rebase 命令来完成 2个/多个 commits 的合并
$ git rebase -i HEAD~2
# $ git rebase -i HEAD~n
# vim 编辑,把最后面的一条/多条 commit 的 `pick` 改成 `s`
`pick` 9b7d63b docs: just for test => `s` 9b7d63b docs: just for test
#
# 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
# s: 使用该 commit, 但是要把它合并到前面一条 commit 中去 ✅
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
在本地确认 commits 已经完成合并,这时候就可以继续推送到远程,让 PR 也更新掉
git push -f origin feat-xxx
这里需要有一个-f参数来强制更新,合并了 commits 本质也是一种冲突,需要冲掉远程旧的 commits 记录。
demo
5 commits => 1 commit ✅
$ git rebase -i HEAD~5
# vim edit 第一次,修改 `pick` => `s`
# vim edit 第二次, 编辑 commit message ✅
$ git push
https://github.com/xgqfrms-GitHub/git-combine-history-commits/
??? shit 截图丢失了 WTF
查看云端历史版本, 找回 ??? 并没有 ❌
GitHub 上找回来了
https://github.com/xgqfrms-GitHub/git-combine-history-commits/pull/2
# 进入 edit
$ it rebase -i HEAD~5
# 退出 edit
# :qa
pick => s
pick b6630b4 delete Travis CI
s 166fd52
s 763eee3 markdown
s d2a7124 PR testing
s 466c20a some description here
# Rebase e33798b..466c20a onto e33798b (5 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 [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# 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
#
# These lines can be re-ordered; they are executed from top to bottom.
合并多个历史 commits, 用于 PR,减少 code review 成本 ✅
delete #3
#5
commit
# $ git push -f origin feat-xxx
$ git push -f
这里需要有一个-f参数来强制更新,合并了 commits 本质也是一种冲突,需要冲掉远程旧的 commits 记录。
https://www.cnblogs.com/xgqfrms/p/16457911.html
5 个 commits ❌
ready combine commits
## main -> main
目前就一个 main 分支呀, 没有 feature 分支
1 个 commit ✅
GitHub PR & Squash and Merge All In One
GitHub 上 merge PR 时合并多个 commits 提交 ✅
https://www.cnblogs.com/xgqfrms/p/16464515.html
修改过去的提交记录
amend 修正
# 如果指定提交之后再次指定提交,就会显示提交清单。
# 请在清单里找出要修改的提交,将该行的 “pick” 改成 “edit”,之后保存并退出。
$ git rebase -i <commit>
# 接着,编辑要修改的文件,保存文件之后指定--amend选项,以执行提交。
$ git commit --amend
# 最后,指定--continue选项以执行rebase。
$ git rebase --continue
https://backlog.com/git-tutorial/cn/reference/log.html#sec3
GitHub PR & git commits squash ❌
https://github.com/lodash/lodash/pull/4756
https://github.com/lodash/lodash/pull/4756/commits/a1484b5aaef68113766f81808386161e172c794c
refs
https://www.cnblogs.com/daniel-hutao/p/open-a-pr-in-github.html#六我提交了一个-pr然后遇到了问题-abcdefg
https://backlog.com/git-tutorial/cn/
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!