How to revert to origin's master branch's version of file

前端 未结 3 1108
醉酒成梦
醉酒成梦 2021-01-29 17:00

I\'m in my local computer\'s master branch of a cloned master-branch of a repo from a remote server.

I updated a file, and I want to revert back to the original version

相关标签:
3条回答
  • 2021-01-29 17:30

    I've faced same problem and came across to this thread but my problem was with upstream. Below git command worked for me.

    Syntax

    git checkout {remoteName}/{branch} -- {../path/file.js}
    

    Example

    git checkout upstream/develop -- public/js/index.js
    
    0 讨论(0)
  • 2021-01-29 17:34

    If you didn't commit it to the master branch yet, its easy:

    • get off the master branch (like git checkout -b oops/fluke/dang)
    • commit your changes there (like git add -u; git commit;)
    • go back the master branch (like git checkout master)

    Your changes will be saved in branch oops/fluke/dang; master will be as it was.

    0 讨论(0)
  • 2021-01-29 17:41

    Assuming you did not commit the file, or add it to the index, then:

    git checkout -- filename
    

    Assuming you added it to the index, but did not commit it, then:

    git reset HEAD filename
    git checkout -- filename
    

    Assuming you did commit it, then:

    git checkout origin/master filename
    

    Assuming you want to blow away all commits from your branch (VERY DESTRUCTIVE):

    git reset --hard origin/master
    
    0 讨论(0)
提交回复
热议问题