简体   繁体   English

Git拉失败,现在有数十个未跟踪的文件

[英]Git pull fails, now dozens of untracked files

Occasionally when a pull fails and I end up with dozens of untracked files. 有时,当拉取失败时,我最终会得到数十个未跟踪的文件。 These files appear to be all the files changed after the last pull. 这些文件似乎是上次拉动后更改的所有文件。 eg: 例如:

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

I can solve this problem with: 我可以使用以下方法解决此问题:

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

What's the best way to resolve this situation? 解决这种情况的最佳方法是什么?

Try this in order first: 请先尝试以下步骤:

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

Then if you don't have request try the same lines you post (git clean or reset). 然后,如果您没有请求,请尝试发布相同的行(git clean或reset)。

Finally if you have conflicts remove them. 最后,如果您有冲突,请将其删除。

Another way to do it, though not neccessarily better: Do what git tells you to do. 这样做的另一种方法(尽管不一定更好):执行git告诉您的操作。

Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time. 存放会带走工作目录的脏状态(即,已修改的跟踪文件暂存的更改) ,并将其保存在未完成的更改堆栈中,您可以随时重新应用它们。
- Git - Stashing -Git-藏匿

git pull failed, you have many untracked files that were 'pulled' but then the pull was aborted and the files stayed. git pull失败,您有许多“拉”的未跟踪文件,但随后拉取被中止,文件被保留。 Now: 现在:

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

Note that this will also get rid of any untracked files you had before pulling. 请注意,这还将消除您在拉动之前拥有的所有未跟踪文件。


There's a second way that git is reommending you: git重新推荐您的另一种方法是:

Please, commit your changes 请提交您的更改

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

This makes sense if you want to keep your local changes and get the new commits from the remote. 如果您想保留本地更改从远程获取新提交,则这很有意义。 You might then encounter merge conflicts which you can resolve. 然后,您可能会遇到可以解决的合并冲突。

Well, for starters, you should probably pull more often so you don't have 140 commits to merge. 好吧,对于初学者来说,您可能应该拉得更多一些,这样就不会有140次提交要合并。

Second, you should either stash or commit your local changes before you try to pull, just as the message says. 其次,正如消息所显示的那样,您应该在尝试拉动之前隐藏或提交本地更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM