Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Need An Account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question. Please subscribe to paid membership

Forgot Password?

Don't have account, Sign Up Here
Please subscribe to paid membership

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Quearn

Quearn Logo Quearn Logo

Quearn Navigation

  • Home
  • Sili AI
  • Quearn Drive
  • Quearn Academy
  • Guest Post (Lifetime Dofollow Backlink)
  • Blog
  • Free Guest Post Submission
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Sili AI
  • Quearn Drive
  • Quearn Academy
  • Guest Post (Lifetime Dofollow Backlink)
  • Blog
  • Free Guest Post Submission
Home/ Questions/Q 1006607
Next
Answered

Quearn Latest Questions

Ragini
  • 6
  • 6
RaginiProfessional
Asked: August 10, 20242024-08-10T19:36:35+05:30 2024-08-10T19:36:35+05:30In: Programmers

What is the HEAD in git?

  • 6
  • 6
head in git
  • 1 1 Answer
  • 353 Views
  • 0 Followers
  • 0

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. [Deleted User]
      Best Answer
      [Deleted User]
      2024-08-10T19:41:05+05:30Added an answer on August 10, 2024 at 7:41 pm
      This answer was edited.
      I always thought HEAD~5 means go to 5 commits before. But it doesn’t carry the GO part of the command. It only carries the reference part of the command.
      What you can do with that reference varies by the command you select In layman terms it’s used to answer the question of: WHERE should I go? To which commit?

      • HEAD means (the reference to the) current commit
      • HEAD~1 means (the reference to) 1 commit before
      • HEAD~ ALSO means (the reference to) 1 commit before
      • HEAD~87 means (the reference to) 87 commits before
      • HEAD~3..HEAD means from 3 commits to current commit (in total 3 commits)

      Usage:

      • git checkout HEAD~1 will actually GO/checkout to 1 commit/reference before
      • git reset HEAD~3 will uncommit your last 3 commits — without removing the changes, ie you can see all the changes made in the last 3 commits together, remove anything you don’t like or add onto it and then commit them all again.
      • git reset --hard HEAD~3 will uncommit your last commit and remove their changes. It will completely remove those changes.
      • git diff HEAD~3 to look into the changes of the last 3 commits
      • git diff someFile HEAD~3 to look into the last 3 changes of a specific file
      • git revert --no-commit HEAD~3..HEAD. Reverts 3 commits, without automatically commiting i.e. you have to do git commit -m yourself.
      • git rev-parse HEAD~2 outputs the SHA of two commit before.
      • See all changes between a pull request and main. It’s a multi-step process.
      git fetch origin/feature22
      git checkout feature22
      git merge-base feature22 main # will return the SHA of their 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
      git reset 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2
      

      You could just do git reset main, but that only works if your colleague who created the pull request has the latest changes with main. If they’re working on a big feature (and haven’t merged with main for a couple days) and you just want to see what additions they have after their last pull from main, then you have to follow the steps above.

      More Detail:

      Make sure you see this answer for What is a detached HEAD. It has some good info on cat .git/HEAD


      Out of scope, but super interesting: Other than HEAD, there are other kinds of heads. See git revisions: ORIG_HEAD

      ORIG_HEAD is created by commands that move your HEAD in a drastic way, to record the position of the HEAD before their operation, so that you can easily change the tip of the branch back to the state before you ran them

      To undo a git merge

      git reset --hard ORIG_HEAD
      

      ORIG_HEAD: is set only as part of something dangerous like a hard reset, where the old head would otherwise have no reference.

      MERGE_HEAD I got this error message after I tried to merge again before concluding an existing merge

      fatal: You have not concluded your merge (MERGE_HEAD exists). Please, commit your changes before you merge.

      To fix this, I had to conclude my merge. Then do another merge. FETCH_HEAD

      records the branch which you fetched from a remote repository with your last git fetch invocation

      CHERRY_PICK_HEAD

      records the commit which you are cherry-picking when you run git cherry-pick.


      More official explanation

      Highly recommend to see this page from the docs. Git as a system manages and manipulates three trees in its normal operation. (By “tree” here, we really mean “collection of files”, not specifically the data structure.) The role of HEAD is:

      Tree Role My Explanation
      Head Last commit snapshot, next [future] parent Something stored in the stone. Fully recorded. Will be the parent record of the next record/commit.
      Index Proposed next commit snapshot Something stored in paper. Is likely to be recorded permanently in the stone. You can remove/alter your paper. Unlike records/commits stored in the stone, if you remove or alter the paper, then you don’t have a record of its previous state.
      Working Directory Sandbox A playground environment. From here you decide if you want to store something in paper, so you can later store in stone.

      HEAD is the pointer to the current branch reference, which is in turn a pointer to the last commit made on that branch. That means HEAD will be the parent of the next commit that is created. It’s generally simplest to think of HEAD as the snapshot of your last commit on that branch.

      tldr HEAD is always moving you in between commits, it doesn’t help you move between staging steps or sandbox.

        • 2

    Sidebar

    Stats

    • Questions 10k
    • Answers 10k
    • Best Answers 3k
    • Users 234k
    • Popular
    • Answers
    • priya

      The header length of an IPv6 datagram is _____.

      • 3 Answers
    • Quearn

      How to approach applying for a job at a company ...

      • 7 Answers
    • priya

      In the IPv6 header,the traffic class field is similar to ...

      • 3 Answers
    • spiralmantra
      spiralmantra added an answer DevOps is a modern approach that combines development and IT… December 5, 2025 at 5:25 pm
    • Quearn
      Quearn added an answer What Makes Quearn’s Guest Post Service Special? ✅ Permanent Placement –… May 19, 2025 at 6:03 am
    • Anonymous added an answer B. dns resolver May 9, 2025 at 4:37 pm

    Top Members

    Stevemark

    Stevemark

    • 185k Points
    Scholar
    Ragini

    Ragini

    • 76k Points
    Professional
    Lark Davis

    Lark Davis

    • 16k Points
    Pundit
    prasanjit

    prasanjit

    • 5k Points
    Teacher
    rohit

    rohit

    • 1k Points
    Begginer

    Trending Tags

    answer computer current data diode education electric flux igbt machine magnetic mcq network poll power quearn question scr study voltage
    Сollaborator

    Latest News & Updates

    • Quearn Support

      Smart Cities: Integrating Drones and Autonomous Vehicles

    • Quearn Support

      Water Wars: How Scarcity Is Shaping Global Politics

    • Quearn Support

      Carbon Footprint 101: What It Is and Why It Matters ...

    • Quearn Support

      Cramming and Stress: How All-Nighters Affect the Brain and Body

    • Quearn Support

      What is procrastination: The Hidden Psychology Behind Delaying Tasks

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help

    Footer

    Quearn

    About

    Quearn is a social questions & Answers Engine which will help you establish your community and connect with other people.

    About Us

    • Blog
    • About Us
    • Contact Us
    • Become a Partner in Quearn
    • Free Guest Post Submission
    • Question Categories
      • AI
      • Analytics
      • Artificial Intelligence
      • Backlinks
      • Blockchain
      • Communication
      • Company
      • Cryptocurrency
      • Education
      • Internet
      • Language
      • Programmers
      • Science
      • SEO
      • University

    Legal Stuff

    • Terms & Conditions
    • Privacy Policy
    • DMCA Policy
    • Cancellation & Refund Policy

    Help

    • Support
    • FAQs
    • Guest Posting
    • Careers
    • Liberty Wire

    Follow

    © 2018-2025 All Rights Reserved by Quearn