Git: branch has lost its history?
Something wierd has happened — my develop branch has lost all it's history till the last commit. Can anyone suggest the reason?
Last things I've done — installed that forked brotherbard GitX and started to use it (primarily for history viewing, but also tried to do on merge). But before develop was staring from master and going in parallel, 'feature-shape-fill' branch was merged into develop two times. I also did git stash in develop.
Right now git log for develop branch just shows the last commit. Doesn't says anything like 'detached'.
* I'm already afraid of GitX (official and this fork), since last weeks smth wierd happened aswell — binary .fla file hasn't been saved for the past evening in several commits. All the text files were fine, but that binary was like 4 commits behind. Other working directory wasn't updating at all while switching between branches (I was working in console and git didn't said about any error, it was fine to him). Donno if it's smth to do with gitx?
upd: Looks like the same problem mentioned here http://groups.google.com/group/gitx/browse_thread/thread/71a0f759d115fee5 Here's what I got:
$ git reflog
157cfca HEAD@{0}: checkout: moving from feature-shape-fill to develop
46a6163 HEAD@{1}: checkout: moving from develop to feature-shape-fill
157cfca HEAD@{2}: commit: Rotated drag tip
7f6c394 HEAD@{3}: commit: TextShapesCanvas is working,
4765eed HEAD@{4}: merge feature-shape-fill: Merge made by recursive.
ed44a2c HEAD@{5}: checkout: moving from feature-shape-fill to develop
46a6163 HEAD@{6}: commit: More tight packaging (thnx to TextLineMetrics),
59b6d2d HEAD@{7}: checkout: moving from develop to feature-shape-fill
ed44a2c HEAD@{8}: merge feature-shape-fill: Merge made by recursive.
67d08b3 HEAD@{9}: commit: Basic grid functionality, need to add text shapes and fix resize-generation
505479c HEAD@{10}: checkout: moving from feature-shape-fill to develop
59b6d2d HEAD@{11}: commit (amend): Simple retrovirus non-optomized algorithm
5ec1b70 HEAD@{12}: commit: Simple retrovirus non-optomized algorithm
b9eaf18 HEAD@{13}: commit: The most ugly suitable version of fill algorithm
757f1b7 HEAD@{14}: checkout: moving fro开发者_如何学Gom feature-shape-fill-predefined to feature-shape-fill
757f1b7 HEAD@{15}: checkout: moving from feature-shape-fill to feature-shape-fill-predefined
757f1b7 HEAD@{16}: checkout: moving from feature-shape-fill-auto to feature-shape-fill
b8e284f HEAD@{17}: commit: Auto fill first steps
757f1b7 HEAD@{18}: checkout: moving from feature-shape-fill to feature-shape-fill-auto
757f1b7 HEAD@{19}: commit: Test document created, components::TextShape base draft
505479c HEAD@{20}: checkout: moving from develop to feature-shape-fill
505479c HEAD@{21}: checkout: moving from master to develop
Looks like they are not lost, but how to get my history back?
The picture you give shows that your develop
branch is detached, if I'm not mistaken.
Since I understand it is based on the master
branch, you could put it back on the master branch:
git rebase master develop
Important: first make a backup of your original .git
directory, before trying the above, as I am not sure that this will produce the result you want.
You could also get a similar result by creating a temporary branch develop2
from master
and merging develop
into it:
git checkout -b develop2 master
git merge develop
Hope this helps! I haven't tried it, so please first back up your .git
directory before trying the above!
To see the history of how just the develop branch changed use:
git reflog show develop
Then either checkout or add branches/tags to older commits by their SHA (or by position e.g. develop@{1}) until you find the last one that was working. For example:
git branch test 7f6c394
Looking at the log these other commits seem to be part of develop as well: ed44a2c, 67d08b3, 505479c
Move the develop branch to the last good commit. You may be able to cherry-pick the other commits back, but it really depends on what caused the error.
I had the exact same problem, the parent SHA for a commit somehow wasn't set and the commit looked like it existed outside of the projects history. The first option provided by EOL will bring your commit back into history, but will lose all of the branch history. (At least, it did for me.) What I ended up doing was looking through my reflog
for the last commit before the one that sent my precious branch into limbo. The lines I saw looked like this:
6d79889 HEAD@{24}: checkout: moving from online-payment-processing to gift-certificates
3da6ec3 HEAD@{25}: commit: fix computation of when to skip processing for special orders
Basically, a commit followed a checkout of a different branch. (In my case, the branch online-payment-processing
was the one in limbo and the 'moving from' message assured me that that previous commit was on my branch.) I knew that the commit at HEAD was the one that was got messed up (as opposed to one further back in history) so I issued the command:
git rebase 3da6ec3 online-payment-processing
and ... poof ... it got fixed (after some conflict resolution) and my branch history was restored.
精彩评论