Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git fails to revert: Found a swap file "COMMIT_EDITMSG.swp"

Tags:

git

I'm using git inside Visual Studio 2013. I'm trying to revert to a specific commit without losing the history leading from that commit to the current commit. In other words, I want git to generate a new commit that has the same snapshot as the specified commit. This is what I've done:

git revert <commit>

where <commit> is the id of the commit I intend reverting to.

Executing the above (in Visual Studio's git command prompt) resulted in the following error:

Found a swap file by the name ".git\.COMMIT_EDITMSG.swp" while opening file ".git\.COMMIT_EDITMSG.swp" NEWER than swap file!

and that

Swap file ".git\.COMMIT_EDITMSG.swp" already exists!

I can't figure out what it means. Did I do it wrong? How am I supposed to revert to a specific commit?

like image 628
snakile Avatar asked Jul 15 '15 12:07

snakile


1 Answers

The swap file is created by the editor vim when you start editing a file; it essentially is a backup file in case the editor crashes.

Now, if the editor launches and finds a swap file, it will usually prompt you to decide what to do, whether to restore the previous editor session or to discard those changes.

If you don’t care about that, you can just delete the swap file first before launching the editor:

rm .git/.COMMIT_EDITMSG.swp

This should remove the swap file, so the next time the editor launches, you no longer get that message and can just work as usual.

like image 163
poke Avatar answered Oct 06 '22 21:10

poke