0

In my local environment I made several changes, then:

$ git log --oneline
2aa8998 Changes 02
5131bfe Changes 01
$ git commit -am "Commit 03"
$ git push

$ git log --oneline
9ca6c56 Changes 03
2aa8998 Changes 02
5131bfe Changes 01

But I noticed what I made a mistake, as I return to commit 2aa8998 before "git commit -am "Commit 03" with the changes without commit?

rpayanm
  • 6,303
  • 7
  • 26
  • 39
  • Not sure if I understand the question, but `git rebase -i HEAD~3` might work for you. – pfnuesel Jun 23 '15 at 00:02
  • You can (see @pfnuesel), but you really shouldn't. Never rebase pushed commits. http://stackoverflow.com/questions/2715085/rebasing-and-what-does-one-mean-by-rebasing-pushed-commits – Jeremy Fortune Jun 23 '15 at 00:30

1 Answers1

1

The push aside, reset is made for this.

$ git reset HEAD^

will move your current local head (master, maybe?) one step up in history, while keeping your local files untouched.

Then for the push (and you should listen to @jeremytwfortune in his comment), you can (but shouldn't) remove it from your remote, by forcing the push.

git push will not work, but git push -f will. -f stands for force, it will apply the push at the risk of losing data.

Gauthier
  • 40,309
  • 11
  • 63
  • 97