Table of Contents
- Related Readings
- Common Tasks
alias gitdiffcommit='git --no-pager diff HEAD' alias gitdiffprod='git --no-pager diff origin/master' alias gitdiffstage='git --no-pager diff' alias gitfilediffcommit='git diff --name-only HEAD' alias gitfilediffprod='git diff --name-only origin/master' alias gitfilediffstage='git diff --name-only' alias gitglog='git log --graph --decorate --all' alias gitlistallbranch='git branch -a' alias gitlistbranch='git branch -vv' alias gs='git status'
The objective is to transform the commit tree from left to right.
1. checkout testing branch
We first need to checkout the testing branch using command
git checkout testing.
2. Rebase testing branch on top of mainline branch
We could achieve this using command
git rebase mainline testing. This gives us the following structure:
Note: The instruction provided by
git rebase commands is useful but confusing. In case of conflict, we need to:
- Resove the conflict.
git addto mark the conflicts as resolved.
- Continue the rebase using
git rebase --continue. Now, there are two possibilities:
- We can move to next step. (Git will ask us to resolve new conficts. It's possible that we need to resolve different conflicts for the same files.)
- Git complains and asks us to check if we forget to execute
git add. Now we need to
git statusand see if there are unresolved conflicts. If we do have unresolved conflicts, go back to step 1.
- (Optional) Execute
git rebase --continueagain. (We will probably get the same complain.)
- Skip the current round using
git rebase --skip
Repeat the process until all conflicts are resolved.
3. Rebase mainline branch on top of testing branch
The objective of this step is to move the pointer of mainline branch to the last commit of the testing branch. After this step, we have
- pointer of mainline branch
- pointer of testing branch
all points to the last commit in the local environment.
4. Squash commits if needed
Note that we should be in the mainline branch now. With our example, if we execute
git status at this point, git should report we are currently 3 commits ahead of the origin/mainline.
If we want to squash commits in the testing branch, we could use command
git rebase -i HEAD~3, which produces the following result:
5. Check the local commit history before push
Perform sanity checks using
git log --graph --decorate --all!
----- END -----
©2019 - 2021 all rights reserved