开发者

git branch messed up

开发者 https://www.devze.com 2023-03-26 12:23 出处:网络
I have开发者_StackOverflow社区 a serious issue happened to my git repository. I had 2 branches previously, and I wrote codes last night and forgot to push to the github. This morning I used the other

I have开发者_StackOverflow社区 a serious issue happened to my git repository. I had 2 branches previously, and I wrote codes last night and forgot to push to the github. This morning I used the other machine and tried fork a new branch and push them up(the codes are stored in dropbox so it doesn't matter which machine I'm using), then git gave me error say: "permission denied". Then I realized that I'm not using my labtop, so I opened up my labtop and tried to get into the branch I just created. But then it seems like I cannot do that, and what was worse, all the codes that I committed on the other machine are gone! I use git branch to see the branch listing and now it's like:

centeredForm (shang's conflicted copy 2011-08-08)
* centeredform
  master
  refinement

where the first "centeredForm" is the branch I created on the other machine, and "centeredform" is the branch I created on my labtop afterwards. Are my codes gone? Or is there a way to restore to previous status?


If it was commited, then it's not lost. There's always the history:

git reflog

Then you can grab the SHA of your last commit, and undo any mess:

git reset --hard <SHA>

IMPORTANT: Backup everyhing first. The reset --hard will delete all non-commited changes.


To see if the commit is still there, and dropbox didn't "misplace" it. Use git rev-parse branchYouLost. This will look up the commit for the that branch.

Than do git cat-file -t SHA_above_command_gave_you

From the looks of your error message I'm assuming this will tell you that this is an invalid object. In which case it would seem that dropbox lost the tip of your branch.

Another option to try and find some your lost commits is to use git reflog and try and see if one of those contains the commit you want. You can use git cat-file -p HEAD@{n} to get the log message and see if it is the one that you are missing.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号