Squash Commits with Git

来源:互联网 发布:数控双头螺纹编程实例 编辑:程序博客网 时间:2024/06/14 20:00
# switch to master branchgit checkout master# ensure our master is up to dategit pull remoteRepoName master

With the master branch up to date, we'll use git rebase to consolidate:

git rebase -i master

That command will show a list of each commit, as such:

pick fb554f5 This is commit 1pick 2bd1903 This is commit 2pick d987ebf This is commit 3# Rebase 9cbc329..d987ebf onto 9cbc329## 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## If you remove a line here THAT COMMIT WILL BE LOST.# However, if you remove everything, the rebase will be aborted.#

Edit the summary shown to you by the rebase command, leaving the commit you want to be the main commit as "pick" and changing all subsequent "pick" commands as "squash":

pick fb554f5 This is commit 1squash 2bd1903 This is commit 2squash d987ebf This is commit 3# Rebase 9cbc329..d987ebf onto 9cbc329## 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## If you remove a line here THAT COMMIT WILL BE LOST.# However, if you remove everything, the rebase will be aborted.#

Write/quit past the editor twice (the second screen would allow you to change the commit message, though I like to keep it the same). At this point, your commits are squashed into one. Run the following command to force a push of the new, consolidated commit:

git push -f

This forced push updates the source repository and our commits have become one. If you had already submitted a pull request at GitHub, the pull request would now show only one commit! With one consolidated commit, code review becomes much, much easier!

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 护士学分卡丢了怎么办 公司电脑只能用内网怎么办 遇见素质低的人怎么办 被素质低的人骂怎么办 对素质差的人怎么办 碰到素质低的人怎么办 和韩国人结婚后工作怎么办 大连明珠卡坏了怎么办 护肤品酒精含量太高怎么办 父母出国三年想孩子怎么办 孩子高考不理想想出国怎么办 交大附中创新班剩余孩子怎么办 棋牌开发公司倒闭了怎么办 7月1日本地流量怎么办 装电池的弹簧生锈了怎么办 电器被电池碱了怎么办 车辆被交警拖走怎么办 香烟熏的眼睛疼怎么办 想在中牟住5天怎么办 腰弯了直不了怎么办 自考科目停考了怎么办 把wlan密码忘了怎么办 滕州不给报新婚怎么办 体内锁水能力差怎么办 别人说你人品差怎么办 面对没素质的人怎么办 遇到很坏的室友怎么办 餐饮员工与顾客发生矛盾怎么办 新员工老员工出现矛盾怎么办 手机移动4g网慢怎么办 碰到素质低的老公怎么办 小孩做事拖拉 没时间观念怎么办 execl表中日期加3.5怎么办 狗狗喜欢咬人怎么办 烧烤一顿吃多了怎么办 派派背包食物不足怎么办 未转变者下不了怎么办 小升初户籍与房产不一致怎么办 小孩在外地读书怎么办计生证明 泉州居住证要半年小孩读书怎么办 孩子上学有兰山户口没有房产怎么办