0

I am on my gh-pages branch and when I

$ git add <file>
$ git commit -m "<message>"

I see

# On branch gh-pages
nothing to commit, working directory clean

Then I will do and see the following

$ git stage
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?

$ git status
# On branch gh-pages
nothing to commit, working directory clean

I tried to dig deeper to figure out whats messed up

$ git log
commit d7122828ef232829e28654f4bc56022829d03722
Author: siddhion <siddhion@gmail.com>
Date:   Wed Jul 24 19:00:19 2013 +0200

    1st push to gh-pages

$ git reflog 
d712282 HEAD@{0}: checkout: moving from master to gh-pages
9bf529e HEAD@{1}: checkout: moving from gh-pages to master
d712282 HEAD@{2}: commit (initial): 1st push to gh-pages

I am not sure what is going on here but before this I was trying to get rid of my last commit trying the following commands

git reset --soft HEAD
git reset --hard HEAD
git reset HEAD
git reset .
git reset

Perhaps I made things worse with those. Not sure. Also I tried

$ git push origin gh-pages 
Counting objects: 1156, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (1141/1141), done.
Writing objects:   6% (70/1156), 2.27 MiB | 680.00 KiB/s   

then I immediately cancel because I don't want that commit/add anymore.

How do I revert/delete that last commit/add and start over clean?

UPDATE

Ok I first followed I am John Galt's answer. I ran

$ git checkout d712282

and got this

Note: checking out 'd712282'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at d712282... 1st push to gh-pages

at this point I really did not know what to do. All I wanted was to be back at my gh-pages branch and no longer have that dam d712282 commit plaguing me. So at that point I

$ git checkout gh-pages

and foolishly I thought the d712282 commit died with the detached head and so I proceeded as I would before doing

git add index.html 

but when I checked to see if had been staged I got

$ git stage
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?

It seemed at this point that nothing changed from before but I kept on just to be thorough. When I tried to run a commit I got

$ git commit -m "added index.html to gh-pages" 
# On branch gh-pages
nothing to commit, working directory clean

and then I did

$ git status
# On branch gh-pages
nothing to commit, working directory clean

I wanted to see what was up and running $ git log gave me

$ git log
commit d7122828ef232829e28654f4bc56022829d03722
Author: siddhion <siddhion@gmail.com>
Date:   Wed Jul 24 19:00:19 2013 +0200

    1st push to gh-pages

There is that same old d712282 commit. I also ran $ git reflog and got

$ git reflog
d712282 HEAD@{0}: checkout: moving from d7122828ef232829e28654f4bc56022829d03722
d712282 HEAD@{1}: checkout: moving from gh-pages to d712282
d712282 HEAD@{2}: checkout: moving from d7122828ef232829e28654f4bc56022829d03722
d712282 HEAD@{3}: checkout: moving from gh-pages to d712282
d712282 HEAD@{4}: checkout: moving from master to gh-pages
9bf529e HEAD@{5}: checkout: moving from gh-pages to master
d712282 HEAD@{6}: commit (initial): 1st push to gh-pages

and this point I tried Geoffrey's suggestion and ran and got

$ git reset --hard d712282
HEAD is now at d712282 1st push to gh-pages

So at this point all I want to do is get rid of d712282 because everytime I try git push origin gh-pages git starting pushing the d712282 commit which has like 1156 files. Way too much. I wants it dead.

  • See http://stackoverflow.com/questions/1338728/how-to-delete-a-git-commit (and also http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging as what you have now is essentially shown in the first three diagrams). – torek Jul 24 '13 at 22:07

2 Answers2

0

If you want to revert a commit you need to reset to the previous commit ID, not HEAD

git reset --hard d712282

git add/commit will do nothing if you have not modified anything.

Geoffrey
  • 10,843
  • 3
  • 33
  • 46
0

You will need to start with git log Or if you need cleaner syntax git log --oneline this will show you your commit history so that you can find the one that you are looking for. Once you have the SHA-1 that goes with the commit you care about (this is why descriptive commit messages are good). You can explicitly checkout that commit as followed

git checkout WHAT_EVER_THE_SHA-1_TAG_IS

That will make your staging index set to that commit and you can continue your work. Also read the notes on log so you know how to get yourself out of these situations, and always be really careful with reset --hard

https://www.kernel.org/pub/software/scm/git/docs/git-log.html

usumoio
  • 3,500
  • 6
  • 31
  • 57