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

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


当前回答

另一种解决的方法 就是先用 Git 隐藏来隐藏任何未承诺的更改, 然后运行

git pull --rebase=interactive -s recursive -X theirs

在交互式的重新基点中,您可以改变您本地所有不想要的放弃承诺, 这将摆脱它们, 并离开您在远程分支的头部, 而不引入合并承诺 。

现在,你可以运行git 藏品申请 如果你有本地藏品 更改了您想要带回来。

其他回答

在窗口上执行此单命令 :

git fetch --all & git reset --hard origin/master

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

. jutignore( )

public/images/*

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

您可能会发现此命令有助于丢弃本地更改 :

git checkout <your-branch> -f

然后进行清理( 从工作树上移走未跟踪的文件) :

git clean -f

如果您想要除去未跟踪的文件之外, 还要删除未跟踪的目录 :

git clean -fd

首先,试一下标准方法:

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