use*_*712 5 git reset git-checkout
克隆存储库后,我无法将该存储库的状态重置为远程分支。
$ git clone <repo>
$ git reset --hard <upstream branch>
fatal: ambiguous argument '<upstream branch>': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]
Run Code Online (Sandbox Code Playgroud)
效果很好的方法是添加前缀origin
$ git reset --hard origin/<upstream branch>
Run Code Online (Sandbox Code Playgroud)
或之前结账
$ git checkout <upstream branch>
$ git reset --hard <upstream branch>
Run Code Online (Sandbox Code Playgroud)
问题:
“将该存储库的状态重置为远程分支”是什么意思?
如果您想要本地分支等于远程分支,只需使用 **git checkout*:
git checkout -b local_branch_name origin/remote_branch_name
Run Code Online (Sandbox Code Playgroud)
如果您的工作区很脏,并且想要删除任何添加/修改的文件,您可以键入:
git clean -f
git checkout -f -b local_branch_name origin/remote_branch_name
Run Code Online (Sandbox Code Playgroud)