Домой United States USA — software Git Reset HEAD

Git Reset HEAD

175
0
ПОДЕЛИТЬСЯ

Git HEAD is an important concept. In this guide you will learn everything about Git HEAD, Git detached HEAD, and how to fix it.
Join the DZone community and get the full member experience. Recently, I published a detailed guide about Git reset HEAD. In case you need a downloadable pdf copy, you can get it here. In this Git HEAD guide, I will explain all about the basics. You will learn about the detached head and how you can reset it with a few simple git commands. Git branches are super helpful, and you can create a new branch, merge a branch, or delete a branch, per your requirements. There are many git commands that you can use to manage your branches in git. When you use the git checkout branch, HEAD points out the last commit. In simple terms, you can say Git HEAD is the current branch. Whenever you check out a branch or create a new branch, Git HEAD transfers it. HEAD is a reference to the last commit in the current check-out branch. In the repository, HEAD points to the starting point of the current branch at all times. In other words, the HEAD is a pointer to the parent of the next commit or where the next commit will occur since it is where the repo left off. More specifically, HEAD is a moving pointer that may or may not refer to the current branch, but it always refers to the current commit. The Caret (^) is the parent of the Commit. The tilde (~) is a shorthand character for a row of several characters (^). The equivalence of HEAD~2 to HEAD^^. And, in the same way, the equivalence of HEAD~3 to HEAD^^^. The default used is 1, if no number is mentioned, so HEAD~ is equal to HEAD^. You can see where the current Git HEAD is pointing to with the following command: In my case, it’s pointing to the main branch, so the following output will appear on the shell: And, if you are interested in the commit hash Id on which head is pointing, you can use the following command to display it: The HEAD is the branch (or a commit) you are now looking at. Note: to signify this status, we have used all capital letters. In lowercase, you can see «head» printed. It may refer to all of the «heads» in a repository while «head» is written in lowercase. For example, «main» is a «head» since a branch is a reference to it. There could be a variety of heads in a repository, but just one HEAD. Maybe this sounds complicated.

Continue reading...