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

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


当前回答

我也有同样的问题,而且出于某种原因, 即使一个干净的Git -f -d也不会这样做。这就是为什么:由于某种原因,如果你的文件被Git忽略(通过.gitignore 项,我假设),它仍然费心于在稍后的拉动中覆盖这个文件,但清洁不会去除它,除非你加上 -x。

其他回答

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

git clean

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

这将删除所有未承诺的更改, 然后拉动 :

git reset --hard HEAD
git pull

首先,试一下标准方法:

git reset HEAD --hard # To remove all not committed changes!
git clean -fd         # To remove all untracked (non-git) files and folders!

警告: 上面的命令只有在您没有执行时才会导致数据/ 文件丢失 ! 如果您不确定, 请先从整个仓库文件夹中获取备份 。

然后再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次,再拉一次

如果上面没有帮助,而你不在乎你的未追踪文件/目录(在万一情况下先备份),请尝试以下简单步骤:

cd your_git_repo  # where 'your_git_repo' is your git repository folder
rm -rfv *         # WARNING: only run inside your git repository!
git pull          # pull the sources again

这将删除所有 git 文件( 免罪 . git/ dir , 在那里您全部负责) , 并再次拉动它 。


为什么Git 重置头 - 硬有时会失败?

. givatitribitte 中有 eol=lf 规则的. givatitribittes 文件中的自定义规则 。 givatitrifittes 文件中的 eol=lf 规则 。 givatripittes 中 . givatripittes 中 eol=lf 规则 . givatripittes 中 可能会通过将 折叠线条转换为 if in some text file filef. 如果是这样的话, 您必须执行这些kilf/lf 规则( 在 git status 状态中查看这些规则) , 或者尝试 : git config ore.autcilf 错误来暂时忽略它们 。 当您使用不支持许可属性的文件系统时, 文件系统无法兼容 。 例如, 您有两个仓库, 一个在 Linux/ mac (ext3/hf) 上 (ext3/hf) 。

如果您不总是想要粘贴分支名称, 或者您想要在脚本中自动显示此分支名称, 这里是一个通用的解决方案 。

git fetch
git reset --keep origin/$(git rev-parse --abbrev-ref HEAD)

如果您也想重置本地更改 :

git fetch
git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)

您也可以使用此命令添加一个弹片别名 :

alias gplf='git fetch && echo "HEAD was at $(git rev-parse --short HEAD)" && git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)'

只是做做

git fetch origin branchname
git checkout -f origin/branchname // This will overwrite ONLY new included files
git checkout branchname
git merge origin/branchname

来避免所有不想要的副作用,例如删除您想要保存的文件或目录等。