我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。

错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖


当前回答

"我的地方变化很小,或者我的地方变化不起作用。 我只是想重置一切 回到原创。 我知道所有的地方变化都会丢失。"

如果情况是这样的话:

git reset --hard
git pull

其他回答

对于那些不喜欢重置的人,我喜欢这样的做法:


git checkout branchname      # go to your branch
git fetch origin branchname  # fetch the remote
git checkout -b backup       # optionally, mark your remote as a backup
git branch -f branchname origin/branchname # force your local branch to be equal to the fetched origin/branchname


您可能会发现此命令有助于丢弃本地更改 :

git checkout <your-branch> -f

然后进行清理( 从工作树上移走未跟踪的文件) :

git clean -f

如果您想要除去未跟踪的文件之外, 还要删除未跟踪的目录 :

git clean -fd

在窗口上执行此单命令 :

git fetch --all & git reset --hard origin/master

看起来最好的办法是首先做到:

git clean

以删除所有未跟踪的文件,然后继续使用通常的 Git 调用...

我读过所有答案,但我在找一个命令来做这个。 这就是我所做的。在.gitconfig 中添加了一个 Git 化名。

[alias]
      fp = "!f(){ git fetch ${1} ${2} && git reset --hard ${1}/${2};};f"

您的命令以

git fp origin master

等于

git fetch origin master
git reset --hard origin/master