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

问题描述 投票:1回答:3

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

$:/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

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

git
3个回答
0
投票

首先尝试这个:

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

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

最后如果你有冲突删除它们。


0
投票

另一种方法,虽然没有必要更好:做git告诉你做什么。

Stashing采用工作目录的脏状态 - 即修改后的跟踪文件和分阶段更改 - 并将其保存在一堆未完成的更改中,您可以随时重新应用这些更改。 - 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

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


-1
投票

好吧,对于初学者来说,你应该更频繁地拉,所以你没有140次提交合并。

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

© www.soinside.com 2019 - 2024. All rights reserved.