如何使用git stash检索未跟踪的文件

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

所以我用一些未跟踪的文件藏起来

git stash --include-untracked

然后切换到另一个分支。

如果我看看哪些变化被隐藏了:

backend/infinispan-rar/pom.xml                     |   12 ++++++++++--
backend/pom.xml                                    |   13 +++++++++++--
backend/test/pom.xml                               |    3 +--
.../main/resources/com/mojiva/testDbContext.xml    |    6 +++---
data/mojiva.xml                                    |    2 +-
dbmigration/pom.xml                                |   16 ++++++++++------
.../main/resources/db/changelogs/issue-17544.xml   |    4 ++--
pom.xml                                            |   11 +++++++++++

然后我尝试使用检索这些文件

git stash pop

得到这个:

backend/activator/effective.pom already exists, no checkout
backend/adverter/src/test/java/com/mojiva/presenter/RequestParamReplacerTest.java already exists, no checkout
backend/dao/.cpath already exists, no checkout
backend/dao/.e0 already exists, no checkout
backend/dao/PutObjectStoreDirHere/defaultStore/Recovery/TransactionStatusManager/#22#/0_ffffc0a86465_cfd2_5016b5cb_1 already exists, no checkout
backend/dao/dep.tree already exists, no checkout
backend/feeds-test/.e0 already exists, no checkout
backend/feeds-test/dep.tree already exists, no checkout
data/wurfl-patch.xml already exists, no checkout
run/linksDB.log already exists, no checkout
run/linksDB.properties already exists, no checkout
run/linksDB.script already exists, no checkout
Could not restore untracked files from stash

请注意,没有一个文件是相同的?

这里发生了什么?

谢谢!

git
3个回答
5
投票

从下面提到的关于如何应用使用-a而不是-u创建的存储的博客:

找到存储的提交:

git log --graph --all --decorate --oneline

看看这个

git checkout <sha>

重置父母:

git reset HEAD~1

创建一个干净的藏匿处:

git stash -u

您现在可以结帐master并应用新的藏匿处。

https://blog.tfnico.com/2012/09/git-stash-blooper-could-not-restore.html#


3
投票

我今天完成了同样的事情,没有找到有用的帮助。所以我做了这个伎俩:

  • git checkout stash

这将创建一个临时分支。然后你可以在上面申请藏匿。

  • git stash apply
  • 在安全的地方手动复制所有已更改的文件。
  • 忽略临时分支并签出到原始分支。
  • 首先将文件粘贴到找到它们的位置。

完成。

这个问题很老了。但答案可能会帮助像我这样的人。所以...


-3
投票

您应该忽略日志和其他非源代码的文件。无论哪种方式,您都可以添加--force来覆盖它们。

在您的情况下发生的事情是,您弹出的文件将会尝试覆盖您在工作文件夹中已有的文件。如果你在那里有重要的工作,git将安全地发挥作用,而不是盲目地覆盖它们。

最好的建议是清理你的设置:

  1. 将不是源代码的文件(如日志文件)添加到.gitignore文件中。
  2. 配置文件应该具有抽象的连接字符串,因此每次切换分支或环境时都不会更改它们(在不同的计算机上使用存储库)。请参阅progit.org/book中git属性章节中的smudge / clean脚本。

如果您是新手,请在webchat.freenode.net上打开#git IRC频道:)

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