Git pull失败了,现在有几十个未跟踪的文件

时间:2012-02-06 23:25:42

标签: git

有时候拉动失败,我最终得到了几十个未跟踪的文件。这些文件似乎是最后一次拉动后更改的所有文件。例如:

$:/var/django/freshplum$ sudo git pull
Updating acb962a..eaf8c43
error: Your local changes to 'plum/api/resources/product.py' would be overwritten by merge.  Aborting.
Please, commit your changes or stash them before you can merge.


$:/var/django/freshplum$ git status
# On branch master
# Your branch is behind 'origin/master' by 140 commits, and can be fast-forwarded.
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    plum/api/resources/feed.py
... dozens of files ...
#   modified:   plum/www/views.py
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   plum/bacon/tests/models/segment.py
... dozens of files ...
#   plum/www/templates/www/internship.html
no changes added to commit (use "git add" and/or "git commit -a")

我可以用以下方法解决这个问题:

git reset --hard HEAD
git clean -f -d
git pull

解决这种情况的最佳方法是什么?

3 个答案:

答案 0 :(得分:0)

先按顺序尝试:

git add --all (or specific files)
git commit -a (or specific)
git pull
git push origin master (or your branch)

然后,如果您没有请求,请尝试发布相同的行(git clean或reset)。

最后,如果您有冲突,请将其删除。

答案 1 :(得分:0)

另一种实现方法,尽管不一定更好:执行git告诉您的操作。

  

隐藏会占用您的工作目录的脏状态-即,   您的修改后的跟踪文件分段更改-并将其保存在   一堆未完成的更改,您可以随时重新应用。
  -Git - Stashing

git pull失败,您有许多“拉”的未跟踪文件,但拉取操作被中止而文件仍然保留。现在:

git add -A        # stage all files so they are now stashable
git stash         # stash them - the working dir is now clean
git pull          # pull
git stash drop    # forget the stashed changes. Alternatively: git stash pop

请注意,这还将删除您在拉动之前拥有的所有未跟踪文件。


git重新推荐您还有另一种方法:

  

请确认更改

git add -A
git commit -m "new commit"
git pull

如果您想保留本地更改 并从远程获取新提交,这很有意义。然后,您可能会遇到可以解决的合并冲突。

答案 2 :(得分:-1)

嗯,对于初学者来说,你应该更频繁地拉动,这样你就不会有140次提交合并。

其次,在尝试提取之前,您应该隐藏或提交本地更改,就像消息所说的那样。

相关问题