links:: Source Control for Test Automation with Git MOC
4.2 Rewriting the History of a Branch
Do not use --amend
on master branch.
Example 1 - Commit change with mistake, then fix mistake without creatng ne wcommit (using --amend
)
git checkout -b feature/test5-lisa-amend
Make Chenges
Find Mistake
Fix Mistake
git add .
git commit --amend
Default Editor Opens, Change Commit Message or Leave as it is
Done
Example 2 - Create 2 aditional changes on the branch before, each in a separate commit. then cleanup the branch y squasing all commits into a single one.
- commit changes: "add test5-lisa-amend"
- commit changes: "test6-lisa-rewrite-hist"
- commit changes: "test3-lisa-rewrite-hist"
- rebase interactively (fixup, fixup, reword)
- push to remote repo
- create and approve PR to merge to master
- fetch and merge to local master
cd .\repos\tau-the-bowlingstar\ git checkout -b feature/test5-lisa-amend git status git commit -am "add test5-lisa-amend" git add . git status git commit --amend git log git status git commit -am "add test6-lisa-rewrite-hist" git commit -am "add test7-lisa-rewrite-hist" git log --oneline git rebase -i HEAD~3 git log --oneline git push --set-upstream origin feature/test5-6-7-squashed git push --set-upstream origin feature/test5-lisa-amend git status git fetch git status git checkout master git merge
Danger
Don't rewrite history of a public brunch