我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制在 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 add *
git commit -a -m "local file server commit message"
然后在发生冲突时获取更改并覆盖
git fetch origin master
git merge -s recursive -X theirs origin/master
- x 是一个选项名称, 而它们就是该选项的价值。 您选择使用它们的更改( 另一个选项是我们的更改) , 如果有冲突 。
我有一个类似的问题。 我必须这样做:
git reset --hard HEAD
git clean -f
git pull
如果您不总是想要粘贴分支名称, 或者您想要在脚本中自动显示此分支名称, 这里是一个通用的解决方案 。
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
来避免所有不想要的副作用,例如删除您想要保存的文件或目录等。
首先,试一下标准方法:
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) 。