One way to find the SHA of a commit is to view the Git log. To checkout or switch to a specific commit, you can also use git checkout and pass the SHA of the commit instead of a branch name.Īfter all, branches are really just pointers and trackers of specific commits in the Git history. (my-feature)$ How to checkout a specific commit There is also a handy shortcut for returning to the previous branch you were on by passing - to git checkout instead of a branch name: (my-feature)$ git checkout. To switch to an existing branch, you can use git checkout again (without the -b flag) and pass the name of the branch you want to switch to: (my-feature)$ git checkout master How to switch to an existing branch in Git Here you can see a new branch created called my-feature which was branched off of master. The new branch's history will start at the current place of the branch you "branched off of."Īssuming you are currently on a branch called master: (master)$ git checkout -b my-feature This will create a new branch off of the current branch. To create a new branch in Git, you use the git checkout command and pass the -b flag with a name. To do this, you can use the git checkout command. This will keep the history the same, and it will not change the record of the branch’s history.Switching branches is something you'll need to do often in Git. You could also make a new commit that signifies exactly the same state of the venture as f414f31.Also, the commits you did after f414f31 will no longer be included in the history of your master branch. Yet, this is rewriting the history of your branch, so if you share your branch with anyone it is best to not use this option. This can be done with git reset –hard f414f31. You could make your current branch to point to the older commit instead. (You can find that via git log or by viewing any history browser.) You then have a few different choices dependent on what you would like to do: Here is another example, presume that the good commit that you want to go back to is f414f31. HEAD shows your current branch, or current commit, meaning that all git reset –hard HEAD will do is to throw away all of the uncommitted changes you have.
0 Comments
Leave a Reply. |