我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
在 Windows 上执行此单命令 :
git fetch --all & git reset --hard origin/master
其他回答
所需经费:
解决方案 :
获取获取与 a 具有清洁联 联 年 月 日 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 月 日 月 的 月 月 月 日 月 月 日 月 的 月 月 月 月 日 月 月 月文件 文件和目录目录目录目录忽略忽略. jutignore( )和硬重置重置至来源来源.
git stash --include-untracked
git fetch --all
git clean -fdx
git reset --hard origin/master
警告: 警告:git clean
删除所有未跟踪的文件/目录,无法撤销。
有时只是偶尔clean -f
如果您有未跟踪的主管, -d 选项也需要 :
# WARNING: this can't be undone!
git reset --hard HEAD
git clean -f -d
git pull
警告: 警告:git clean
删除所有未跟踪的文件/目录,无法撤销。
考虑使用-n
(--dry-run
) 旗号先行。这将显示要删除的内容,但实际上没有删除任何内容:
git clean -n -f -d
示例产出:
Would remove untracked-file-1.txt
Would remove untracked-file-2.txt
Would remove untracked/folder
...
对于那些不喜欢的人reset
我喜欢这个方法:
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 fetch origin branchname
git checkout -f origin/branchname // This will overwrite ONLY new included files
git checkout branchname
git merge origin/branchname
因此,您可以避免所有不想要的副作用, 比如删除您想要保存的文件或目录, 等等 。
我认为答案很可怕,但虽然赫奇猪的答案可能更好,但我不认为它能有那么优雅。fetch
和merge
使用定义的战略, 从而保存您本地的更改, 只要它们不是您试图强制覆盖的文件之一 。
git add *
git commit -a -m "local file server commit message"
git fetch origin master
git merge -s recursive -X theirs origin/master
-X
是一个选项名称,并且theirs
是此选项的值。 您选择使用their
更改(另一个选项是ours
如果有冲突,则更改。