Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
HEAD~5means 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.HEADmeans (the reference to the) current commitHEAD~1means (the reference to) 1 commit beforeHEAD~ALSO means (the reference to) 1 commit beforeHEAD~87means (the reference to) 87 commits beforeHEAD~3..HEADmeans from 3 commits to current commit (in total 3 commits)Usage:
git checkout HEAD~1will actually GO/checkout to 1 commit/reference beforegit reset HEAD~3will 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~3will uncommit your last commit and remove their changes. It will completely remove those changes.git diff HEAD~3to look into the changes of the last 3 commitsgit diff someFile HEAD~3to look into the last 3 changes of a specific filegit revert --no-commit HEAD~3..HEAD. Reverts 3 commits, without automatically commiting i.e. you have to dogit commit -myourself.git rev-parse HEAD~2outputs the SHA of two commit before.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/HEADOut of scope, but super interesting: Other than
HEAD, there are other kinds of heads. See git revisions: ORIG_HEADTo undo a
git mergeMERGE_HEAD I got this error message after I tried to merge again before concluding an existing merge
To fix this, I had to conclude my merge. Then do another merge. FETCH_HEAD
CHERRY_PICK_HEAD
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
HEADis:tldr HEAD is always moving you in between commits, it doesn’t help you move between staging steps or sandbox.