Git merge without auto commit

后端 未结 5 518
轻奢々
轻奢々 2020-12-02 03:36

Is it possible to do a git merge, but without a commit?

\"man git merge\" says this:

With --no-commit perform the merge but pretend the          


        
相关标签:
5条回答
  • 2020-12-02 04:02

    You're misunderstanding the meaning of the merge here.

    The --no-commit prevents the MERGE COMMIT from occuring, and that only happens when you merge two divergent branch histories; in your example that's not the case since Git indicates that it was a "fast-forward" merge and then Git only applies the commits already present on the branch sequentially.

    0 讨论(0)
  • 2020-12-02 04:09

    If you only want to commit all the changes in one commit as if you typed yourself, --squash will do too

    $ git merge --squash v1.0
    $ git commit
    
    0 讨论(0)
  • 2020-12-02 04:11

    I prefer this way so I don't need to remember any rare parameters.

    git merge branch_name
    

    It will then say your branch is ahead by "#" commits, you can now pop these commits off and put them into the working changes with the following:

    git reset @~#
    

    For example if after the merge it is 1 commit ahead, use:

    git reset @~1
    

    Note: On Windows, quotes are needed. (As Josh noted in comments) eg:

    git reset "@~1"
    
    0 讨论(0)
  • 2020-12-02 04:17

    When there is one commit only in the branch, I usually do

    git merge branch_name --ff
    
    0 讨论(0)
  • 2020-12-02 04:20

    Note the output while doing the merge - it is saying Fast Forward

    In such situations, you want to do:

    git merge v1.0 --no-commit --no-ff
    
    0 讨论(0)
提交回复
热议问题