我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
在 Windows 上执行此单命令 :
git fetch --all & git reset --hard origin/master
其他回答
我试图在三角2Webpack-Starter上使用第2号材料分支, 并度过了一段很漫长的时光。 这是我唯一可以下载和使用该分支的方法。
git clone --depth 1 https://github.com/angularclass/angular2-webpack-starter.git
cd angular2-webpack-starter/
git checkout -b material2
打开工程文件夹, 删除所有非隐藏的文件和文件夹。 留下所有隐藏的文件和文件夹 。
git add .
git commit -m "pokemon go"
git reset --hard
git pull origin material2
(当编辑器弹出时,按“:wq”键,然后按输入)
现在你准备好了
警告:
对已跟踪文件的本地更改将丢失 。 @ 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
所需经费:
解决方案 :
获取获取与 a 具有清洁联 联 年 月 日 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 月 日 月 的 月 月 月 日 月 月 日 月 的 月 月 月 月 日 月 月 月文件 文件和目录目录目录目录忽略忽略. jutignore( )和硬重置重置至来源来源.
git stash --include-untracked
git fetch --all
git clean -fdx
git reset --hard origin/master
看起来最好的办法是首先做到:
git clean
删除所有未跟踪的文件,然后继续按常规git pull
...
所有这些解决方案的问题在于,它们要么过于复杂,要么是一个更大的问题,就是它们从网络服务器上移除了所有未跟踪的文件,我们并不想这样做,因为服务器上总是有需要的配置文件,而不是Git仓库。
以下是我们使用的最干净的解决方案:
# Fetch the newest code
git fetch
# Delete all files which are being added, so there
# are no conflicts with untracked files
for file in `git diff HEAD..origin/master --name-status | awk '/^A/ {print $2}'`
do
rm -f -- "$file"
done
# Checkout all files which were locally modified
for file in `git diff --name-status | awk '/^[CDMRTUX]/ {print $2}'`
do
git checkout -- "$file"
done
# Finally pull all the changes
# (you could merge as well e.g. 'merge origin/master')
git pull
第一个命令获取最新数据 。
第二次命令检查是否正在将任何文件添加到存储库中,并从本地存储库中删除那些会造成冲突的未跟踪文件。
第三个命令检查所有本地修改的文件 。
最后,我们努力更新最新版本, 但这次没有任何冲突, 因为回购中的未追踪文件已经不存在了, 所有本地修改过的文件都已经和存储库一样了。