我想以这样一种方式将更改推送到远程 Git 存储库,即不会远程记录自上次拉取以来对本地存储库产生影响的所有提交。
实际上,"big change 2"
一旦我推送到远程注册表中,就应该忘记多个本地更改日志消息(或总结,例如如下例所示)。许多“小”本地提交应该显示为一个“大”远程提交。所以我想阅读这样的日志消息:
git log remote branch
# big change 1
git log branch
# small change 1
# small change 2
# big change 2
git push remote branch
git log remote branch
# big change 1
# big change 2
这是否可以通过git
命令实现,如果可以,如何实现?
是的,这叫做压扁。为此,我通常使用交互式 rebase 功能。
首先,在最旧的提交之前找到你想要成为压缩提交的一部分的提交:
$ git log --oneline
701c7f8 (HEAD -> master) commit c
4c0270a commit b
8ca1f6e commit a
bb0a92c (origin/master) previous commit
然后做git rebase -i <commit>
:
$ git rebase -i bb0a92c
您配置的编辑器将打开,向您显示作为 rebase 操作一部分的提交列表,从最旧的开始:
pick 8ca1f6e commit a
pick 4c0270a commit b
pick 701c7f8 commit c
# Rebase bb0a92c..701c7f8 onto bb0a92c (3 commands)
#
# 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
# d, drop = remove commit
将前三行更改为如下所示:
pick 8ca1f6e commit a
squash 4c0270a commit b
squash 701c7f8 commit c
或者,实际上,第一个字母就足够了:
pick 8ca1f6e commit a
s 4c0270a commit b
s 701c7f8 commit c
保存并退出编辑器。另一个编辑器实例会给你编辑提交信息为生成的挤压提交最终的结果将是一个包含提交提交的变化的机会8ca1f6e
,4c0270a
,701c7f8
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句