我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
一种比较容易的方式是:
git checkout --theirs /path/to/file.extension
git pull origin master
这将在 Git 上的文件上覆盖本地文件
其他回答
一种比较容易的方式是:
git checkout --theirs /path/to/file.extension
git pull origin master
这将在 Git 上的文件上覆盖本地文件
您可以在您的工程基准文件夹中以文件忽略该文件 :
. jutignore( )
public/images/*
然后拉动修改,然后从您的 gitignore 文件中删除该行 。
对于那些不喜欢重置的人,我喜欢这样的做法:
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 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 origin branchname
git checkout -f origin/branchname // This will overwrite ONLY new included files
git checkout branchname
git merge origin/branchname
来避免所有不想要的副作用,例如删除您想要保存的文件或目录等。