Text
$ ls .git
HEAD
config
description
hooks
info
objects
refs
1. Commit
2. Tree
3. Blob
4. Annotated tag
⇒ Ref = Reference
⇒ 'user-friendly alias' for a hash
⇒ use to see the SHA-1 commit hashes
$ git log
⇒ Git uses HEAD file to store latest commit info
⇒ HEAD file is a symbolic ref for the current branch
⇒ Ammended commits are new commits
⇒ Old commit is completely removed from history
$ git reset --soft HEAD^
* Changes are unstaged but
still there
$ git reset HEAD~2
* Changes are unstaged but
still there, check git reflog HEAD starts at 0
$ git reset path/to/filename
* Restores the file to the latest version
in HEAD, changes are preserved
$ git checkout path/to/filename
* Restores the file to the latest version
in HEAD, changes are dropped
$ git revert commit-hash
* Reverts a commit with another commit,
doesn't amend history.
$ git commit --amend
$ git add filename
$ git commit --amend --no-edit
1
2
⇒ Moving a branch onto a new base commit
⇒ Rebasing onto master will take all commits from master and apply your branch commits on top one by one
$ git rebase -i master
$ git rebase -i master
⇒ Let's squash commit 2 into 1
⇒ Let's edit commit 3
Pick, Squash & Edit
Squashing
Squashing: Amending the message
Squashing: save
Edited message 3
Continue rebase
Done!
$ git config --global rerere.enabled true
⇒ reuse recorded solution
⇒ no need to deal with the same rebase conflicts again!
$ git reflog
⇒ reflog = referene log
⇒ records when the tips of branches and other references were updated in the local repository.
⇒ never rebase after merge
⇒ after code is shared use merge not rebase
⇒ only rebase before pushing
⇒ amend and undo things locally only before pushing