简体   繁体   English

在没有git commit的情况下,如何在git add和git checkout之后找回我的差异?

[英]How can I get my diff back after git add and git checkout without git commit?

I modified some files in branch A, and then I use git add to add these modified files. 我在分支A中修改了一些文件,然后使用git add添加了这些修改后的文件。 But I forgot to use git commit to commit the modifications to the current branch. 但是我忘记了使用git commit commit将修改git commit到当前分支。 Then I used git checkout B to switch to another branch. 然后,我使用git checkout B切换到另一个分支。 When I switched to branch A again, I found nothing modified can be found here. 当我再次切换到分支A时,我发现这里没有任何修改。 Is there any way that I can get the modified files back? 有什么办法可以找回修改过的文件?

If git allowed you to switch branch, even with uncommitted changes, those changes are carried to the branch you switched to. 如果git允许您切换分支,即使有未提交的更改,这些更改也会被带到您切换到的分支。 So if you check diff between those two branches, it wont show any change. 因此,如果您检查这两个分支之间的差异,则不会显示任何更改。 Try to take diff with any other base branch. 尝试将diff与其他任何基本分支合并。 hope 希望

git add normally writes the object into the object database. git add通常将对象写入对象数据库。 If it is no longer reachable from the index or any commit, it will be a dangling blob. 如果无法通过索引或任何提交来访问它,则它将是一个悬挂的Blob。

$ git fsck --no-reflogs | grep 'dangling blob'
dangling blob 5cd8df407a53f3cf1a00d7df9b92973fc7124649
dangling blob a15ac56b6ac98b0b26c4d30bd299cf5cea817b83
dangling blob a052e2e82624bfa14d7004a30e971cfc543d3759
dangling blob b3cae5cf028ad4728b344193a7c6fe4e76e36af3
dangling blob bb428320e3f8496ee844dfe1826e5f705e47b0c8
dangling blob aa9bc6e7a3078a91a895f9ade9ecb0d3f46783a0
dangling blob 0094f013e9120ac2168248245ee492f1c551754d
dangling blob 896c4a4752fab07a7be22cc068c50d4b8021c8a9
dangling blob f6fc725dc3f01cedee7933651e202fa1e46101a4
$ git cat-file -p 5cd8df407a53f3cf1a00d7df9b92973fc7124649
...

You can print them out one-by-one to try to find what you lost. 您可以一张一张地打印出来,以查找丢失的内容。 (See the --lost-found option also.) (另请参见--lost-found选项。)

I found them in the stash. 我发现他们藏在里面。 After git add most of the files, I use git stash expecting to put the remaining files to stash. 在git添加大多数文件之后,我使用git stash期望将其余文件存储。 But it seems the modified files are all put to the stash whether they've been added using git add or not. 但是,无论是否使用git add都添加了修改后的文件,它们似乎都被存放了。

暂无
暂无

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

相关问题 如何在Git中压缩提交,以便可以将我的上一次提交与结帐进行比较,而看不到临时提交? - How can I squash a commit in Git so that I can diff my last commit against the checkout without seeing the interim commits? Git:如何签出提交并将其合并回我的分支? - Git: How do I checkout a commit and merge it back into my branch? 来自commit的git checkout文件后,git diff显示没有变化? - After git checkout file from commit, git diff shows no changes? 检查git diff后,如何忽略一些我不想添加到此提交中的文件中的更改? - After checking git diff, how can I ignore changes in a few files that I dont want to add to this commit? Git:如果不提交,我怎样才能回到我的MASTER? - Git: How Can I get back to my MASTER without committing? git checkout和git pull后如何找回修改后的文件? - How to get back modified file after git checkout and git pull? git 错误:`git add` 添加了比我预期的更多的文件,而 `git diff` 在提交后丢失了它们 - git bug: `git add` added more files then I expected and `git diff` is missing them after the commit 进行git checkout时丢失了工作,我该如何找回它 - Lost work doing a git checkout, how can I get it back 如何使git commit历史记录恢复正常? - How do I get my git commit history back to normal? 如何在存储库上的标签之间获取git diff而不进行克隆/检出 - How to get git diff between tags on repository without cloning/checkout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM