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


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.

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                                                                                                    

Pasted image 20230102202932.png|500


Don't rewrite history of a public brunch

Pasted image 20230102203149.png|500