0

Say I'm working on a project and I'm making various commits as I go along

A - B - C - D - E

And I realise that I made a mistake and need to do git reset to go back to version C.

So I then carry on making commits like this: C - D2 - E2 - F2 - G2 etc.

Where D2 is different to D, E2 is different to E etc.

I then realise that I was right in the beginning, and I need to get back to E.

As long as I have kept a note of the SHA of version E, is this possible by doing git reset hjsdkgjdfg where hjsdkgjdfg is the hash of E? I've heard git 'cleans up' (deletes) loose ends every now and then - would D and E be classed as 'loose ends'? Does it depend on the type of reset I have done: soft, mixed, hard?

Bearing in mind I'm a beginner, is this the correct sort of workflow? Or is this a terrible way of working?

Thanks

4

1 回答 1

2

Yes, if you remember the hash you can get back to it. You might want to use git checkout or git branch rather than git reset, though. You're right that git cleans up occasionally - you'll see it when it happens, because you'll get some messages about "garbage collecting."

To be safe, you can keep a branch pointing at your old commit, and then you'll be able to access it symbolically rather than by remembering the hash.

If you need to find an old hash, but you don't remember it, git reflog can help you find it. You can also do tricks like:

 git checkout @{yesterday.at.3.pm}

If you know roughly the time you want to go back to.

于 2013-05-22T17:28:38.913 回答