Question

I (stupidly) have not committed or pushed changes on a project for a few days. Tonight, I accidentally created a commit with no message. Using Atlasssian's Sourcetree I thought "oh let me add a message to that before I push this" - and right clicked and selected "revert".

I'm not entirely sure what other options I selected after that trying to get everything back to the way it was, but right now I am terrified to click anything else for fear of losing several hours of work. If you look at my screenshot below, I would like to make the highlighted commit ("MASTER 1 ahead no message") the version in my working copy AND the most recent commit in my repo.

What should I do?

enter image description here

Was it helpful?

Solution

The idea would be, since you haven't pushed anything yet, to:

git stash
git reset --hard HEAD~
git commit --amend

That would allow you (in command line) to move the HEAD (resetting the index and the working tree, hence the importance of stashing any work in progress first), and edit the commit message.

You should be able to move HEAD from SourceTree (SRCTREE-770, supported since 1.3b3), but command-line can be more precise in this case.

Revert has created another commit which cancel the previous one: if you see your working tree is modified because of it, the reset --hard is here to reset everything to your previous commit (the one without commit message).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top