0 votes
in Git by

 How to undo the most recent commits in Git?

1 Answer

0 votes
by

Details

You accidentally committed wrong files to Git, but haven't pushed the commit to the server yet. How can you undo those commits from the local repository?

Solution

$ git commit -m "Something terribly misguided"      
$ git reset HEAD~                                   # copied the old head to .git/ORIG_HEAD
<< edit files as necessary >>                       
$ git add ...                                       
$ git commit -c ORIG_HEAD                           # will open an editor, which initially contains the log message from the old commit and allows you 

Related questions

+1 vote
asked Feb 10, 2020 in Git Slack Integration by miceperry
0 votes
asked Aug 16, 2020 in Git by RShastri
...