HEAD points to the latest commit
Each git commit adds a node with its short hash: 261c13d. HEAD marks your current commit: it points to main, main to the latest.
Each git commit adds a node with its short hash: 261c13d.
HEAD marks your current commit: it points to main, main to the latest.
Each git commit adds a node with its short hash: 261c13d. HEAD marks your current commit: it points to main, main to the latest.
A mistaken change to greeting.txt lives only in the working tree.
git restore goes back to the last commit: the change is lost for good.
A mistaken change to greeting.txt lives only in the working tree. git restore goes back to the last commit: the change is lost for good.
A commit with a typo in its message: Add farewel.
--amend creates a new one, f3e279c; the old one leaves the history.
With --no-edit it adds signature.txt: another hash. Unshared commits only.
A commit with a typo in its message: Add farewel. --amend creates a new one, f3e279c; the old one leaves the history. With --no-edit it adds signature.txt: another hash. Unshared commits only.
git revert adds a commit with the opposite change of Change greeting to Spanish.
The original stays in the history: the safe choice for shared commits.
git revert adds a commit with the opposite change of Change greeting to Spanish. The original stays in the history: the safe choice for shared commits.
A new commit. git reset --soft HEAD~1 moves HEAD to its parent.
The commit leaves the history; its changes stay in the staging area.
A new commit. git reset --soft HEAD~1 moves HEAD to its parent. The commit leaves the history; its changes stay in the staging area.
Another commit and back again, with --mixed, the default mode.
Staging matches HEAD: tasks.txt returns to the working tree.
Another commit and back again, with --mixed, the default mode. Staging matches HEAD: tasks.txt returns to the working tree.
One more commit, then git reset --hard HEAD~1: all matches HEAD.
tasks.txt no longer exists. An uncommitted change would be gone for good.
One more commit, then git reset --hard HEAD~1: all matches HEAD. tasks.txt no longer exists. An uncommitted change would be gone for good.
It looks lost, but git reflog records every place HEAD has been.
There is bdf42a1, the commit you deleted with --hard.
git reset --hard bdf42a1 goes back to it, and tasks.txt returns.
It looks lost, but git reflog records every place HEAD has been. There is bdf42a1, the commit you deleted with --hard. git reset --hard bdf42a1 goes back to it, and tasks.txt returns.
What was in a commit can almost always be recovered with git reflog.
What was never in a commit is lost with restore or reset --hard.
--amend and reset rewrite history; for shared commits, use git revert.
What was in a commit can almost always be recovered with git reflog. What was never in a commit is lost with restore or reset --hard. --amend and reset rewrite history; for shared commits, use git revert.