Git Pull失败,现在有数十个未跟踪的文件 [英] Git pull fails, now dozens of untracked files

查看:518
本文介绍了Git Pull失败,现在有数十个未跟踪的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

另一种方法,尽管不一定更好,但可以做一些:git告诉你去做.

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 pull失败,您有许多拉"的未跟踪文件,但拉取被中止,文件保留了下来.现在:

git pull failed, you have many untracked files that were 'pulled' but then the pull was aborted and the files stayed. 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.

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

There's a second way that git is reommending you:

请提交您的更改

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.

这篇关于Git Pull失败,现在有数十个未跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆