0

I have 2 devices, I pushed something from device A, and I switched to device B, I found the commit I did in device B is not what I wanted anymore.

I want to discard the commit and use all code in device A, which is the latest version in my master branch, what do I do?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Sharon Chai
  • 507
  • 1
  • 6
  • 20
  • 1
    Possible duplicate of [How to undo the most recent commits in Git?](https://stackoverflow.com/questions/927358/how-to-undo-the-most-recent-commits-in-git) – phd Apr 12 '18 at 13:29

1 Answers1

0

If you just want to "discard" the commit you can use the revert command.

git revert

git revert <sha> will add a new commit which will revert (undo) the given commit. The revert will create a new commit which will generate a path opposite the given commit so you will have the original code in the first commit and the removal of this code in the new commit

git reset

In case the commit(s) you wish to discard are on the top of your branch and you have permission to force push than you can use reset. The limitations here are that you can force push and that there is no other commit in between the reset range that you wish to keep.

git revert = Undo the given commit and add new commit of the undo
git reset = Move the HEAD of the branch to the desired point by "cutting" off the commits from the branch

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • git reset make more sense, I don't see the point of doing git revert when I want to roll back or move on with my code. – Sharon Chai Apr 12 '18 at 06:48