The problem of GIT local branch and stash content error disappearing

Time:2021-4-11

For a local project that has been updated for a long time, GIT log suddenly reported an error:

[email protected]:~/android/project/kernel/.git$ git log .
fatal: your current branch ‘project-dev’ does not have any commits yet

If git status, all files are found to be new

If git branch – V, the local branch information disappears

If git stash list, there is no message

It seems that even if git itself is so good, it can’t avoid its own mistakes-_-

1、 Solve git log:

Check the. Git / objects folder and find that all the submissions are there, indicating that it is helpful

Ls. Git / refs / heads folder. I found my project dev branch missing

Usually, I work in SecureCRT environment and save the operation records automatically. Therefore, it is easy to retrieve the original commit information through grep – RN ‘git log’. Therefore, the latest commit ID of the project dev branch is 1f37a1b5706b3877c693bab220a31d312043fc1c

So we execute vi.git/refs/heads/project-dev and save 1f37a1b5706b3877c693bab220a31d312043fc1c in this file

Git log and git branch – V, the original submitted information is back

2、 Solve the problem of missing git stash list content

Cat. Git / logs / refs / stash file, find the stash ID you want:

[email protected]:~/android/project/kernel$ cat .git/logs/refs/stash
0000000000000000000000000000000000000000 6d83090b5d140597866f32b5dbbca642acab3cba …     On project-dev: enable HDMI display
… / /… Indicates omitted content
25ccdba070ac09929c6f2a1f13b7d29a4b59df5b 8866f78b20047093ff8d1a517868ccce688a5c4b …     On project-dev: wifi&bt temp

Among the above, the original content is not corresponding to any stash submission. 6d83090b5d140597866f32b5bcbca642acab3cba is the first. 8866f78b20047093ff8d1a517868ccce688a5c4b is the last. The content you want to find is the content submitted by “WiFi & BT temp”, and the corresponding submission is 8866f78b20047093ff8d1a517868ccce688a5c4b

So, execute git show 8866f78b20047093ff8d1a517868ccce688a5c4b to see if it is correct

Execute the following command again to save the stash as a diff file:

git show 8866f78b20047093ff8d1a517868ccce688a5c4b > wifi.bt.diff

Finally, execute git apply to input diff file

git apply wifi.bt.diff

Do the same for other stash ID content you want to save

So far, this article about git local branch and stash content error disappeared is introduced here. For more related git local branch and stash error content, please search previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!