git push之后想撤銷這次的修改該怎么做?


git push過后撤銷修改

  1. 使用git reset --hard 要回滾的版本號 ,再 git reset 最新的版本號
    操作:首先對測試.txt文件進行三次修改

    文件里面有內容1 2 3,現在使用git reset --hard 回滾到1上面,git提示HEAD is now at 2a1d20f 1 也就是head位於1上面
    然后git push的時候會提示:
error: failed to push some refs to 'https://github.com/466879168/Article.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

然后git reset 最新版本號 然后add commit -m push之后就OK了
2. 使用git reset –soft
3. 使用git reset –mixed

三者區別:

  • git reset –soft 不會改變stage(暫存區)區,僅僅將commit回退到了指定的提交
  • git reset –mixed 不會改變工作區,但是會用指定的commit覆蓋stage區也就是清空暫存區
  • git reset –hard 使用指定的commit的內容覆蓋stage區和工作區


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM