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

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


当前回答

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

git reset --hard HEAD
git pull

其他回答

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

. jutignore( )

public/images/*

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

在 Windows 上执行此单命令 :

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

对于那些不喜欢的人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 cleangit reset工作。 我必须将冲突文件从git index在每个未跟踪的文件中使用以下脚本 :

git rm [file]

那样我就能好好拉了

不要用git reset --hard这将抹去他们完全不可取的变化,相反:

git pull
git reset origin/master
git checkout <file1> <file2> ...

您当然可以使用git fetch代替git pull因为它显然不会合并, 但如果你通常拉它, 继续拉在这里是有道理的。

所以这里发生的事情就是git pull 更新您的源/ 主管参考; git reset 更新本地分支引用与来源/主管相同,不更新任何文件,所以您的检查状态没有变化;git checkout 将文件返回到您的本地分支索引状态需要时。如果在现场和上游主控上添加了完全相同的文件,索引已经与重置之后的文件匹配,因此在普通情况下,不需要做git checkout完全没有

如果上游分支也包含您想要自动应用的承诺,您可以跟踪进程上微妙的变异:

git pull
git merge <commit before problem commit>
git reset <problem commit>
git checkout <file1> <file2> ...
git pull