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

后端 未结 4 660
孤独总比滥情好
孤独总比滥情好 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:27

    Yes, you can visit any arbitrary revision with "git checkout" as you describe. If you ask for an arbitrary revision rather than a branch, git will not have any obvious way to keep track of what changes you make, though. You can see where you were before by consulting the reflog ("git reflog show") - but in general, you would have been on a branch before so presumably just want to change back to that with "git checkout master" or similar.

    Note that this method won't automatically deal with uncommitted changes in your workspace--- either commit or stash your changes before moving between branches, or use "git checkout -m" to carry them around as you move (and be prepared to deal with merge conflicts if the changes you're carrying aren't trivial).

    I think recent git versions have introduced the shorthand "@{-1}" for "where I was before I last moved", which might actually be what you want in this case. (I haven't used it, just read about it in the release notes).

提交回复
热议问题