git:给我回购,nuke当地的一切,我不在乎

Log*_*der 18 git

git是否有任何拉/结账'核选项'来获得回购?我不关心任何冲突,我不需要任何我当地的东西,只是想要货物,所以我可以工作.

[编辑]澄清我的问题:

$ git pull
error: Your local changes to the following files would be overwritten by merge:

<...files I couldn't care less about...>

Please, commit your changes or stash them before you can merge.
error: The following untracked working tree files would be overwritten by merge:

<...more files I couldn't care less about...>
Run Code Online (Sandbox Code Playgroud)

Mau*_*ord 14

更好地让你理解各种git命令,然后找到你现在需要的那个,因为你会多次提出这种情况,并且在抱怨和责备git的同时学习零碎.

编辑:我继续尝试所有选项,这应该做到这一点.感谢pauljz在评论中.

git clean -df # remove untracked files AND directories
git reset HEAD --hard # revert any uncommitted changes
Run Code Online (Sandbox Code Playgroud)

以上应该是你所需要的.

其他选择:

git pull -f # replace local files even if you have unpushed commits.
Run Code Online (Sandbox Code Playgroud)

要么

git reset HEAD --hard # remove unchanged, uncommitted files
git pull
Run Code Online (Sandbox Code Playgroud)

要么

git clean -f # remove untracked files (uncommitted files)
git pull
Run Code Online (Sandbox Code Playgroud)


Tom*_*ner 5

有时,其他答案中列出的步骤不起作用,因为[咆哮已编辑]。在这种情况下,你的“战术核武器”选项是:

(如有必要)重置未提交的本地更改,以便您可以切换:

git reset --hard HEAD
Run Code Online (Sandbox Code Playgroud)

创建并切换到不同的本地分支:

git checkout -b tempBranch
Run Code Online (Sandbox Code Playgroud)

强制删除存在问题的(本地副本)分支:

git branch -D targetBranch
Run Code Online (Sandbox Code Playgroud)

从远程签出并切换到目标分支的干净副本:

git checkout -b targetBranch origin/targetBranch
Run Code Online (Sandbox Code Playgroud)

通过删除您创建的临时本地分支进行清理:

git branch -D tempBranch
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,“战略核武器”选项是删除该存储库并再次克隆它。


Kla*_*urn 4

您始终可以删除现有存储库的整个文件夹,然后使用以下命令创建一个新文件夹git clone

  • 这可能需要很长时间,具体取决于存储库/互联网连接的大小,一般来说相当浪费,而且几乎是“我放弃”的方法。人们应该学习正确重置一切的命令。这样下次你需要做的时候就会变得更容易。 (2认同)