0

I threw a new commit on GitHub on branch develop from the local repository. This is the last commit in this project https://github.com/JonkiPro/popcorn/commits/develop

Rename the project, modules and packages.

the problem is that I noticed that in certain places I did not make the correct change and I would like to withdraw this last commita from branch develop.

That's why I want to ask what is the git command to undo the last commita from a particular branch (develop)?

JONKI
  • 535
  • 5
  • 10
  • 24
  • `git revert ` This will create a new commit that undoes all the changes of the commit hash provided. IF you want to recreate the same commit, and not add another, you can stage your changes to add to the commit, and run `git commit --amend`, this will delete and recreate the commit, overwriting history. If you have pushed this to a remote, you will need to then force the push, or it will be rejected. I would advise going the first option and creating a new commit. – Matt Clark May 07 '18 at 21:23

1 Answers1

0

First you do a git log -1.
This will give you a last commit details. Copy the last commit Id(hint::Its a long string).

Next you do a git revert commitId, with commit id copied earlier.
This will create another commit for you which will roll back all the stuff you pushed earlier. Just push this commit and you are good to go.

  • So this means that the last commit will be ```Add the war and the test modules. Code refactoring```, because I do not want a commit to be shown ```Revert "Add the war and the test modules. Code refactoring"```? – JONKI May 07 '18 at 21:39
  • Nope you do not delete a commit in GIT. You add another commit which undoes what was done earlier. You can try Matt's suggestion above `git commit --amend` to modify history. I have not personally tried it. – saurav kumar May 07 '18 at 21:51