簡體   English   中英

Git拉失敗,現在有數十個未跟蹤的文件

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

有時,當拉取失敗時,我最終會得到數十個未跟蹤的文件。 這些文件似乎是上次拉動后更改的所有文件。 例如:

$:/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 add --all (or specific files)
git commit -a (or specific)
git pull
git push origin master (or your branch)

然后,如果您沒有請求,請嘗試發布相同的行(git clean或reset)。

最后,如果您有沖突,請將其刪除。

這樣做的另一種方法(盡管不一定更好):執行git告訴您的操作。

存放會帶走工作目錄的臟狀態(即,已修改的跟蹤文件暫存的更改) ,並將其保存在未完成的更改堆棧中,您可以隨時重新應用它們。
-Git-藏匿

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

如果您想保留本地更改從遠程獲取新提交,則這很有意義。 然后,您可能會遇到可以解決的合並沖突。

好吧,對於初學者來說,您可能應該拉得更多一些,這樣就不會有140次提交要合並。

其次,正如消息所顯示的那樣,您應該在嘗試拉動之前隱藏或提交本地更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM