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

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


当前回答

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


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 branch -m [branch_to_force_pull] tmp
$ git fetch
$ git checkout [branch_to_force_pull]
$ git branch -D tmp

就是这样!

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

git 获取 -- all

随后是:

git 重置 - 硬源/ master 。

我读过所有答案,但我在找一个命令来做这个。 这就是我所做的。在.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

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

git clean

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

您可以尝试 Git pull - 力 或者可能通过使用 Git 藏起来来隐藏你的行为 然后运行 git pull 。