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

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


当前回答

“我的地方变化很小,或者我的地方变化不起作用。我只想将一切重置回到原创。我知道我的地方变化都将失去。”

如果情况是这样的话:

git reset --hard
git pull

其他回答

我也有类似的问题,我不得不这么做

git reset --hard HEAD
git clean -f
git pull

比较容易的方式是:

git checkout --theirs /path/to/file.extension
git pull origin master

这将用 Git 上的文件覆盖您的本地文件

对于那些不喜欢的人reset我喜欢这个方法:


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 restore .

。指目录中的所有文件。

您可以在您的工程基准文件夹中以文件忽略该文件 :

. jutignore( )

public/images/*

然后拉动修改,然后从您的 gitignore 文件中删除该行 。