0

I am working on Git repo for current project, In my project some abc.php file is there.

My Branch is develop

At present my local and remote branch codes are same, now I have done some Changes in abc.php. Need to move(remote Branch).

So I have done following way.

git add -A --> adding files

git commit -m "changes done in abc.php" --> files are committed

then I have to use git push origin develop --> to push my changes to remote branch

But now I realize, I don't want my latest commit.. Is it possible to ignore my latest commit ?? Please help me with solution

Thanks in Advance!..

kishan kurivella
  • 589
  • 4
  • 7
  • 19

3 Answers3

6

If you have committed junk but not pushed,

git reset --soft HEAD~1

HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. --soft option will delete the commit but it will leave all your changed files "Changes to be committed", as git status would put it.

If you want to get rid of any changes to tracked files in the working tree since the commit before head use --hard instead. Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,

git revert HEAD

This will create a new commit that reverses everything introduced by the accidental commit.

Rohit Poudel
  • 1,793
  • 2
  • 20
  • 24
0

Try:

git reset HEAD~1

git push -f

snoopy
  • 328
  • 1
  • 12
0

To cancel a commit is to apply the inverse of its diff!

We can redirect the diff of the commits to cancel to the command patch --reverse

git diff HEAD^ | patch --reverse

To make it simpler, there is git revert

For example, to cancel the last three commits:

git revert HEAD~3..HEAD

Or to cancel a particular commit: :

git revert 444b1cff

Then you can push cleanly the commit obtained on the server. Any collaborators who had based their work on canceled commits will have to manage the conflicts at the right time ..

Gwen
  • 311
  • 1
  • 3
  • 3