What's the difference between “squash” and “fixup” in Git/Git Extension?

前端 未结 6 1919
夕颜
夕颜 2020-12-07 15:14

I\'ve been using Git Extensions for a while now (it\'s awesome!) but I haven\'t found a simple answer to the following:

Sometimes, when typing a com

相关标签:
6条回答
  • 2020-12-07 15:46

    I do not know what Git Extensions does with it specifically, but git rebase has an option to automatically squash or fixup commits with squash! or fixup! prefixes, respectively:

       --autosquash, --no-autosquash
           When the commit log message begins with "squash! ..." (or "fixup!
           ..."), and there is a commit whose title begins with the same ...,
           automatically modify the todo list of rebase -i so that the commit
           marked for squashing comes right after the commit to be modified,
           and change the action of the moved commit from pick to squash (or
           fixup).
    

    The difference between squash and fixup is that during the rebase, the squash operation will prompt you to combine the messages of the original and the squash commit, whereas the fixup operation will keep the original message and discard the message from the fixup commit.

    0 讨论(0)
  • 2020-12-07 15:50

    If the question is what's the difference between squash and fixup in git when doing git rebase --interactive, then the answer is the commit message.

    s, squash <commit> = use commit, but meld into previous commit

    f, fixup <commit> = like "squash", but discard this commit's log message


    For example:

    pick 22a4667 father commit message
    squash 46d7c0d child commit message # case 1
    # fixup 46d7c0d child commit message # case 2
    

    The commit message after rebasing in case 1 would be:

    father commit message
    
    child commit message
    

    while the commit message in case 2 is:

    father commit message
    # no sub messages
    
    0 讨论(0)
  • 2020-12-07 15:51

    Why not ask git itself? When you rebase with git-bash, it says:

    pick 512b1d7 (some comment)
    # Rebase 621b2e4..512b1d7 onto 621b2e4 (1 command)
    #
    # 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 <commit> = like "squash", but discard this commit's log message
    # x, exec <command> = run command (the rest of the line) using shell
    # 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.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    D:/code/fenixito-legacy-api/.git/rebase-merge/git-rebase-todo [unix] (11:57 23/10/2019)                                         1,1 start
    "D:/code/xxx/.git/rebase-merge/git-rebase-todo" [UNIX] 27L, 1170C
    

    So you see:

    s, squash = use commit, but meld into previous commit

    f, fixup = like "squash", but discard this commit's log message

    0 讨论(0)
  • 2020-12-07 15:53

    Simply put, when rebasing a series of commits, each commit marked as a squash, gives you the opportunity to use its message as part of a pick or reword commit message.

    When you use fixup the message from that commit is discarded.

    0 讨论(0)
  • 2020-12-07 15:58

    From git-rebase doc, "interactive mode" section:

    If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit message for the folded commit is the concatenation of the commit messages of the first commit and of those with the "squash" command, but omits the commit messages of commits with the "fixup" command.

    0 讨论(0)
  • 2020-12-07 16:00

    I tinkered with git extensions and couldn't get it to squash many commits into one. To do that, I had to resort to the command line and found this post helpful

    git rebase -i Head~2
    

    This is interactive rebase, and note the following:

    • ~2 here refers to how many commits you want to involve in this operation, including the current head
    • You have to edit the subsquent interactive edit window, leave the first item as "pick" and replace subsequent lines with "squash". The instructions in the link above are much clearer if this is opaque.
    0 讨论(0)
提交回复
热议问题