

Ali Heydari
Rewriting history
Squash merging
git merge --squash bugfix/signup
git commit -m "[meaningfull message that represent all changes in bugfix/signup]"
git merge --no-merged
git branch -D bugfix/signup
Cherry-picking
git cherry-pick <commit-sha>
git restore --source=ali/feat/dark-theme -- src/_app.ts
Rebasing
- in target branch run:
git rebase other-branch
- in case of conflict use:
git rebase --continue|--skip|--abort
Why rewrite history
Why we need history?
Because we need to know WHAT was changed, WHY and WHEN.
Bad history:
- Poor commit messages
- Large commits
- Small commits
Tools:
- Squash small, related commits
- Split large commits
- Reword commit messages
- Drop unwanted commits
- Modify commits
The golden rule of rewriting history
Don't rewrite PUBLIC history!
If you need to rewrite history, you should be rewriting your PRIVATE history.
Undoing commits
git reset --hard HEAD~1
Reverting commits
git revert HEAD|<COMMIT_SHA>
Recovering lost commits
git reflog
Amending the last commit
git commit --amend
git commit --amend --no-edit
Amending an earlier commit
git rebase -i <COMMIT_SHA>|<BRANCH_NAME>
- choose the commit you want to amend
- edit the commit
git add .
git commit --amend
git rebase --continue
git rebase --skip
git rebase --abort
Dropping commits
git rebase -i
- write
drop
in front of the commit you want to drop or remove the commit line
Rewording commit messages
git rebase -i
- write
reword
in front of the commit you want to reword
Reordering commits
git rebase -i
- reorder commits
Squashing commits
git rebase -i
- write
squash
in front of the commit you want to squash
Splitting a commit
git rebase -i
- write
edit
in front of the commit you want to split - make changes
- add changes that you want to keep
- commit
- make other changes
- add other changes to staging area
- commit
Attachments: [session video 📺](\\192.168.100.14\Training Courses\git)
Tags:lecture