Search code examples
gitgithubrebasegit-commitgit-interactive-rebase

What does COMMIT WILL BE LOST when rebasing in Git?


#
# 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
# b, break = stop here (continue rebase later with 'git rebase --continue')
# 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.

Is commenting out the line with the commit hash the same as using the DROP keyword?
I'd like to rebase my Pull Request so it only has one commit submitted.


Solution

  • Is commenting out the line with the commit hash the same as using the DROP keyword?

    Yes

    I'd like to rebase my Pull Request so it only has one commit submitted.

    I'm assuming you still want to keep all the changes, but combine it all into one big commit. In that case what you should do is change the pick at the beginning of each commit line (except the very first one) to fixup.

    For example, let's say your rebase prompt looks like this:

    pick b761975 Start a big project
    pick 5239708 Oops fix a bug in the project
    pick a85ecbe Oops fix another bug
    pick 17a2131 Finally the big project is done
    

    If you want to combine that all into one big commit that's titled "Start a big project", edit it as follows:

    pick b761975 Start a big project
    fixup 5239708 Oops fix a bug in the project
    fixup a85ecbe Oops fix another bug
    fixup 17a2131 Finally the big project is done
    

    You could change the first pick to reword if you also want to change the commit message on the big commit.