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

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


当前回答

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

git 获取 -- all

随后是:

git 重置 - 硬源/ master 。

其他回答

我有一个类似的问题。 我必须这样做:

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

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

如果情况是这样的话:

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 --theirs /path/to/file.extension
git pull origin master

这将在 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