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

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


当前回答

而不是与 Git pull 合并, 请尝试一下 :

git 获取 -- all

随后是:

git 重置 - 硬源/ master 。

其他回答

1: 重置为上一个承诺

git reset --hard HEAD

2: 删除未跟踪的文件

git clean -f

3:拉起承诺

git pull

资料来源:

http://git-scm.com/docs/git-reset https://git-scm.com/docs/git-clean/

git restore file_to_override_from_remote

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


i 总结了其他答案。 您可以执行 Git 调用, 且不出错 :

git fetch --all
git reset --hard origin/master
git reset --hard HEAD
git clean -f -d
git pull

警告: 此脚本非常强大, 这样您就可以丢失更改 。

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

如果情况是这样的话:

git reset --hard
git pull