简体   繁体   中英

Need to reverse a GIT commit

I've tried for hours to get back to the previous commit. Can anyone help me? I pushed the master branch to my remote repo (the d34...commit), but it's the d6f (second down) commit I want.

When I try to change to that commit, I get this error: Are you sure you want to checkout 'd6fa4...[truncated]'?

Doing so will make your working copy a 'detached HEAD'

Can anyone please help me to remove that last commit from my develop and master branches? Thank you!

More notes, because I have not explained this problem clearly: When I checkout commit d6fa4... the codebase is exactly what I want. The merge commit (that I already pushed) brought together the master and develop branches. If I check out d6fa4, I get a detached head, but again, the codebase is now correct. The problem is, I cannot figure out how to reset my master and develop branches to THAT commit.

I hope that makes it clearer. Thanks again!!

SourceTree截图

Since you seemed to have pushed the commit, you can do:

git revert d349d18
git push origin master

If you don't care about changing pushed history ( and especially if no one else is working on the repo), do:

git reset --hard d6fa474

( you can do that for both master and develop)

I would suggest against deleting or reverting a pushed commit. Create a new commit that reverts what you've done and push it. If you're working with other people, this can cause a lot of bad things on the repository.

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