Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit gives error: empty commit set passed

Tags:

git

github

When trying to revert to a previous commit, I tried:

git revert --no-commit 0766c053..HEAD

However this gave an error:

empty commit set passed

Question: What does the error mean, and what went wrong with the revert command?

like image 851
Nyxynyx Avatar asked Jul 14 '14 05:07

Nyxynyx


People also ask

How do I allow an empty commit in git?

Git makes this process of pushing an empty commit super simple. It's like pushing a regular commit, except that you add the --allow-empty flag. You can see that the commit has been pushed to your branch without any changes after running the above commands.

What will happen if an empty commit message is entered?

The "Git: Commit Empty" command requires the user to enter a commit message, otherwise it will abort the commit.

How do I add an empty commit message?

Creates an empty commit. Use git commit --allow-empty -m <message> to create an empty commit with the provided <message> .

How do I undo last commit?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


2 Answers

It seems to me that you misused the double dot annotation to specify a commit range.

So your range doesn't return any commits which means that revert can't do anything, since you effictively said "revert no commits".

The gitpro book explains the double dot annotation (link to chapter) pretty solid:

The most common range specification is the double-dot syntax. This basically asks Git to resolve a range of commits that are reachable from one commit but aren’t reachable from another. For example, say you have a commit history that looks like Figure 6-1.

Figure 6-1. Example history for range selection.

You want to see what is in your experiment branch that hasn’t yet been merged into your master branch. You can ask Git to show you a log of just those commits with master..experiment — that means "all commits reachable by experiment that aren’t reachable by master." For the sake of brevity and clarity in these examples, I’ll use the letters of the commit objects from the diagram in place of the actual log output in the order that they would display:

$ git log master..experiment
D
C

If, on the other hand, you want to see the opposite — all commits in master that aren’t in experiment — you can reverse the branch names. experiment..master shows you everything in master not reachable from experiment:

$ git log experiment..master
F
E

like image 191
Sascha Wolf Avatar answered Oct 06 '22 20:10

Sascha Wolf


Remove the ..HEAD part. At least on my system (git v2.7.4) this resolved the issue.

git revert --no-commit 0766c053

like image 20
matt3o Avatar answered Oct 06 '22 19:10

matt3o