Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase interactive drop vs deleting the commit line

Tags:

git

git-rebase

What is the difference from drop in the Git interactive rebase and just deleting the line of the commit?

like image 502
Wazery Avatar asked Mar 07 '16 14:03

Wazery


People also ask

What does dropping a commit in rebase do?

(drop) — If you remove a commit from the interactive rebase file, or if you comment it out, the commit will simply disappear as if it had never been checked in. Note that this can cause merge conflicts if any of the later commits in the branch depended on those changes.

Does rebase delete commits?

Running rebase in interactive mode and executing subcommands like squash or drop will remove commits from your branche's immediate log.

What does git rebase -- Interactive do?

The interactive rebase gives you a script that it's going to run. It will start at the commit you specify on the command line ( HEAD~3 ) and replay the changes introduced in each of these commits from top to bottom. It lists the oldest at the top, rather than the newest, because that's the first one it will replay.

How do you terminate an interactive rebase?

To do this, simply delete all commits and actions (i.e. all lines not starting with the # sign) and the rebase will be aborted!


2 Answers

There is no difference by default; it's just another way to say the same thing.

But, if you set rebase.missingCommitsCheck to warn or error, then removing a line will trigger a warning (useful for detecting a messed-up cut-and-paste).

Then setting the line to drop explicitly tells Git that you want to drop that commit, and no warning is shown for it.

like image 51
Matthieu Moy Avatar answered Oct 18 '22 20:10

Matthieu Moy


There is in fact another small difference:

You can explicitly "drop" all commits. The effect will be the same as a reset.

However if you just delete all lines, then git will tell you "Nothing to do".

Usually you would not use rebase anyway in that case. I learned the difference only when I tried to explain removing a commit with rebase to a co-worker using a dummy commit.

like image 45
Stephen Friedrich Avatar answered Oct 18 '22 19:10

Stephen Friedrich