[英]Failed to pull from git automatically
I have a startup script that is supposed to sync the git repo on the machine with master 我有一个启动脚本,应该将机器上的git repo与master同步
git pull -r origin master
Getting 入门
error: The following untracked working tree files would be overwritten by merge:
file1.py
Folder2/file3.rb
Please move or remove them before you can merge.
Aborting.
tried solving this using 尝试解决这个问题
git clean -df
git clean -dn
git stash
git checkout master
git pull -r origin master
# to pull new branches
git fetch
still getting the error. 仍然得到错误。 How can I ensure successful pull from master? 我怎样才能确保从主人那里获得成功?
[This is done automatically.] [这是自动完成的。]
Thanks 谢谢
If you just want to have the contents from origin/master
in your local copy discarding any local change you have 2 options: 如果您只想让本地副本中的origin/master
内容丢弃任何本地更改,您有两个选择:
git fetch origin && git reset --hard origin/master
. 或者您可以通过运行git fetch origin && git reset --hard origin/master
来更新本地副本,从而放弃对跟踪文件的所有更改。 This is faster than the full clone option because it will only have to fetch the new commits in the remote repo that you don't have locally. 这比完整克隆选项更快,因为它只需要获取本地没有的远程仓库中的新提交。 This has the small problem that your working copy can potentially have more files that you have in the remote repo. 这有一个小问题,即您的工作副本可能包含远程仓库中的更多文件。 Doing git clean -dffx
will remove everything not tracked by git, so you'll end up with a clean copy of the remote repo. 执行git clean -dffx
将删除git未跟踪的所有内容,因此您最终会获得远程git clean -dffx
的干净副本。 error: The following untracked working tree files would be overwritten by merge: 错误:合并将覆盖以下未跟踪的工作树文件:
If you have no important local changes then do hard reset
your local/master
with remote/master
. 如果您没有重要的本地更改,请使用remote/master
hard reset
local/master
remote/master
。
$ git fetch
$ git reset --hard origin/master
NB: Potentially hard reset
dangerous command, since it throws away all your uncommitted changes and local commits that have not in remote/master
. 注意:潜在的hard reset
危险命令,因为它会丢弃所有未提交的更改和本地提交,而不是remote/master
。
Alternative: 替代方案:
Add the untracked files. 添加未跟踪的文件。
$ git add .
Go back to a clean working directory by stashing
. 回到干净的工作目录中stashing
。 Keep your local modifications away and reverts
the working directory to match the HEAD commit
. 保持本地修改并reverts
工作目录以匹配HEAD commit
。
$ git stash
Now pull origin master. 现在拉起源大师。
$ git pull origin master
You have added these two files to the repository, 您已将这两个文件添加到存储库,
file1.py
Folder2/file3.rb
And didn't commit. 并没有承诺。 So if you don't want these files manually delete these files from your repository & your script will work fine after that 因此,如果您不希望这些文件从您的存储库手动删除这些文件,那么您的脚本将在此之后正常工作
Update 更新
If you want a generic way, 如果你想要一个通用的方式,
git clean -f -d
or git clean -fd
要删除目录,请运行git clean -f -d
或git clean -fd
git clean -f -X
or git clean -fX
要删除被忽略的文件,请运行git clean -f -X
或git clean -fX
git clean -f -x
or git clean -fx
要删除忽略和未忽略的文件,请运行git clean -f -x
或git clean -fx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.