1.

Can you explain head in terms of git and also tell the number of heads that can be present in a repository?

Answer»
  • A head is nothing but a reference to the last commit OBJECT of a branch.
  • For every repository, there will always be a default head referred to as “master” or now “MAIN” (as per GitHub) but there is no restriction to the count of heads available. In other words, it can have any number of heads.
  • Usages:

    - To GO or checkout to 1 commit before the latest commit, we use git checkout HEAD~1

    - To uncommit the last 3 commits without losing the changes, we first run git reset HEAD~3. Then we can see the changes made in the last 3 commits and then update it manually and commit it finally.

    - In order to uncommit the last 3 commits and also remove the changes, we can run the command: git reset --hard HEAD~3. This command will COMPLETELY remove all the changes.

    - To look into the changes made in the last 3 commits, we can run git diff HEAD~3

    - To make a new commit by reverting the last 3 commits, we can run the command: git revert --no-commit HEAD~3...HEAD


Discussion

No Comment Found