简体   繁体   中英

How do I undo a revert in Git?

I just started using git, I've been working on a large project. I made an initial commit and didn't commit again for a while. My project is almost done so I decided to mess around with git again and commit the new files in my project, which I did, but didn't push. I read right after that that it's preferred to make small commits, so I decided to delete my last commit and practice making smaller commits from my project. I used git revert and it deleted most of my files!! I read online to 'revert the revert' and used git revert . It said failed to commit and that I needed to commit changes in my project, so I did and tried again making sure to include the correct commit, it failed. I'm semi-panicking, I was almost done and that was a lot of work (for me).

Edit:
Here's the git log:

commit 286f067d7ff46385af05381cfe1b657e60204393 (HEAD -> master)
Author: my username <my email

Date:   Thu Jun 30 19:18:45 2022 -0400

trying to fix this

commit 27dd527567348acecc31cbababa9ddc2a31eacdc
Author: my username <my email>
Date:   Thu Jun 30 16:39:31 2022 -0400

reverted commit

My favorite way (the cleanest possible) to revert a commit is to use git reset

Basically, these are the steps I follow:

  1. Get the commit code to revert to
  2. git reset --hard <code> to return to that commit
  3. Backup the entire project somewhere else in the computer
  4. git pull to return to the latest commit
  5. Erase everything and paste the previous backup
  6. git add .
  7. git commit
  8. git push

I know it may take some time meanwhile some codes do this automatically, but I think it's the safest way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM