如何使用git merge --squash? [英] How to use git merge --squash?

查看:109
本文介绍了如何使用git merge --squash?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程Git服务器,这里是我想要执行的场景:


  • 对于每个bug /特性我创建了一个不同的Git分支


  • 我继续在该Git分支中使用非官方Git消息提交代码

  • $ b
  • 在顶层存储库中,我们必须对官方Git消息中的一个错误进行一次提交。

  • >那么我怎样才能将我的分支合并到远程分支中,这样他们只需要为我的所有签入提交一个提交(我甚至希望为此提供提交消息)?

    解决方案

    说你的错误修复分支叫做 bugfix ,并且你想把它合并到 master $ b $ pre $ g $ c $ git checkout master
    git merge --squash bugfix $ b $ git commit

    这将从 bugfix 分支提交所有提交,将它们压缩为1次提交,并将其与您的 master 分支合并。






    说明

      git checkout master 

    切换到您的 master 分支。

      git merge --squash bugfix 

    接受来自 bugfix 分支的所有提交,并将其与您当前的分支合并。

      git commit 

    从合并的更改中创建单个提交。



    省略 -m 参数可让您在完成提交之前修改草稿提交消息,其中包含压缩提交中的每条消息。


    I have a remote Git server, here is the scenario which I want to perform:

    • For each bug/feature I create a different Git branch

    • I keep on committing my code in that Git branch with un-official Git messages

    • In top repository we have to do one commit for one bug with official Git message

    So how can I merge my branch to remote branch so that they get just one commit for all my check-ins (I even want to provide commit message for this)?

    解决方案

    Say your bug fix branch is called bugfix and you want to merge it into master:

    git checkout master
    git merge --squash bugfix
    git commit
    

    This will take all the commits from the bugfix branch, squash them into 1 commit, and merge it with your master branch.


    Explanation:

    git checkout master
    

    Switches to your master branch.

    git merge --squash bugfix
    

    Takes all the commits from the bugfix branch and merges it with your current branch.

    git commit
    

    Creates a single commit from the merged changes.

    Omitting the -m parameter lets you modify a draft commit message containing every message from your squashed commits before finalizing your commit.

    这篇关于如何使用git merge --squash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆