[英]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.