2
#
# 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.

Julian
  • 33,915
  • 22
  • 119
  • 174
engineer-x
  • 2,173
  • 2
  • 12
  • 25

3 Answers3

3

Yes, drop and the removed line will both result in removing the commit. From the docs:

To drop a commit, replace the command "pick" with "drop", or just delete the matching line

But there are small differences. For example:

  1. Removing all lines will abort the rebase, so that's different than drop all
  2. There is a check that could be enabled to warn/error when lines are missing:

    rebase.missingCommitsCheck: If set to "warn", git rebase -i will print a warning if some commits are removed (e.g. a line was deleted), however the rebase will still proceed. If set to "error", it will print the previous warning and stop the rebase, git rebase --edit-todo can then be used to correct the error. If set to "ignore", no checking is done. To drop a commit without warning or error, use the drop command in the todo list. Defaults to "ignore".

Julian
  • 33,915
  • 22
  • 119
  • 174
2

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.

Flight Odyssey
  • 2,267
  • 18
  • 25
0

Yes. Both are same (commenting a line or drop keyword). The git documentation tells the same thing.

for more information, refer to git rebase documentation

To drop a commit, replace the command "pick" with "drop", or just delete the matching line.

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58