Do you need to create a branch to check out a specific git revision?

后端 未结 4 658
孤独总比滥情好
孤独总比滥情好 2021-02-18 14:45

A common thing I\'d like to do is revert my working copy to a particular revision, do some testing, and then bring it back to the head of my current master. In the past I have

4条回答
  •  时光说笑
    2021-02-18 15:39

    If you want Git to show the tip of some line of changes, you need to have it branched or tagged. But even if you do not make a branch, none of the commits is lost. It stays in the repository as a garbage node (i.e. not reachable through any branch or tag), and is removed only some days/weeks later when you do "git gc".

    So if you want to have an easy access to the changes, it's best to create a temporary branch and work there. If you do commits outside a branch and then checkout another branch, then you will need to use the command "git reflog" or look into the logs (".git/logs" directory) to find out what was the hash of the changes that you lost. When you know the hash, you can do "git checkout hash" or "git checkout -b new_branch hash" and recover the tip.

提交回复
热议问题