简体   繁体   中英

Recommended way with Git to go back to a previous commit

Hy,

I have some commits in my local repository in GIT(commit1, commit2 and commit3).The remote repository is updated with the last commit3. Now I noticed the commit2 and commit3 introduces some bugs and I want go back to commit1. I used a reset commit1 but after I cannot push because the head in the local branch is older than the remote branch and git says I need to update so

  1. What is the recommended way to do it according to GIT, using reset, checkout...?

Thanks

使用“ git revert”创建撤消更改2和3的commit4是最安全的。否则,必须使用push -f,只有在远程服务器允许的情况下,才使用push -f。

If you are sure you want to destroy this 2 commits in the remote repository and annoying all the devs that already fetch them, you just have to do a force push after the reset you did :

git push origin master --force-with-lease 

If origin is your remote and master your local branch...

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