我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
我读了所有的答案,但我正在寻找一个命令来做到这一点。这是我所做的。在.gitconfig中添加了一个Git 化名。
[alias]
fp = "!f(){ git fetch ${1} ${2} && git reset --hard ${1}/${2};};f"
将命令运行为
git fp origin master
等于
git fetch origin master
git reset --hard origin/master
其他回答
警告:
对已跟踪文件的本地更改将丢失 。 @ info: whatsthis
任何本地文件否吉特追踪到的不会受到影响。
第一,更新所有origin/<branch>
最晚的 refs :
git fetch --all # if this doesn't work try `git pull -f` (see comments)
备份当前分支( 例如 )master
):
git branch backup-master
跳转到最新承诺origin/master
并检出这些文件 :
git reset --hard origin/master
git fetch
从远程下载最新数据,不试图合并或重标任何内容。
git reset
将主分支重置为您刚获取的 。--hard
选项选项 更改工作树中的全部文件以匹配文件origin/master
.
[*]值得指出的是,通过从master
在重设前:
git checkout master
git branch new-branch-to-save-current-commits
git fetch --all # if this doesn't work try `git pull -f` (see comments)
git reset --hard origin/master
在那之后,一切旧事,将永居其中;new-branch-to-save-current-commits
.
将丢失未承诺的更改( 即使是第 阶段的更改) 。 请确保隐藏并承诺您需要的一切 。 为此您可以运行以下操作 :
git stash
然后重新应用这些未承诺的修改:
git stash pop
我尝试了大部分我在这里能找到的东西,
有效的是git merge -X theirs
对于那些不喜欢的人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
这个解决方案总是在运行 。
cd $GIT_ROOT_DIRECTORY
git fetch origin/$TARGET_BRANCH
git rm -rf --cached .
git reset --hard origin/TARGET_BRANCH
git clean -df
git pull origin $TARGET_BRANCH
警告,如果您在 gitignore 文件中有任何目录/ * 条目, 这样做将永久删除您的文件 。
有些答案似乎很可怕。 从发生在Lauri身上的可怕意义来看,
相反(给予 > v1.7.6):
git stash --include-untracked
git pull
稍后,您可以清理藏匿历史。
手动,一对一:
$ git stash list
stash@{0}: WIP on <branch>: ...
stash@{1}: WIP on <branch>: ...
$ git stash drop stash@{0}
$ git stash drop stash@{1}
残酷地说,所有 - 一次:
$ git stash clear
当然,如果你想回到你藏的东西:
$ git stash list
...
$ git stash apply stash@{5}