Git Contd…
- In the last session we discussed about merge where a new commit was created with two parents, this is generally referred as three-way-merge
- Cherry picking was done on once commit i.e. we added one commit from one branch to other branch (without merging)
- Cherry picking can also done on sequence of commits
- Lets create a feature_1003 branch with 4 commits in it
- Now if we merge the changes back to rel_tata_v1.0, by default it creates a fast-forward merge, if your organization follows a practice that whenever you merge we need a commit for that, we can create an extra commit (three way merge) by adding (–no-ff)
- Now lets move to the feature_1003 branch
- Now we want all of this 4 commits on rel_wipro_v1.0, so lets cherry-pick range of commits
Special Characters used in Git
- In Git we would be using
- Tilde
~
:- to go back a number of generations
- Caret
^
- double dot
..
Exercise:
- Create a new git repository
- Try to create a branch and create a situation for merge conflict
- Try to create a situation for merge without a conflict.
Rebase
- Consider the following situation
- We need the changes done in master branch after feature branch creation to be part of feature branch, the best way to do it would be as shown graphically below
- Git rebase can exactly do this.
- Consider the following situation
- Now we want changes of master to be part of feature_branches history
- Now execute
git rebase <source branch>
Lets visit the Three areas of Git (Local Repo)
Manipulating History
- Mistakes in previous commit message
- situation
- solution
- situation
- reflog:
- Git keeps track of the updates to the tip of branch using a mechanism called as reference logs or reflog
- Git keeps track of the updates to the tip of branch using a mechanism called as reference logs or reflog
- RESET:
- Git reset has three modes: soft, mixed and hard
- Soft Reset:
- consider the following changes
- Now lets soft reset to second commit
- Changes are not lost
- consider the following changes
- Hard Reset:
- Consider the following changes
- Changes are lost
- Consider the following changes
- Mixed Reset:
- Consider the following changes
- Changes are moved to the working tree (unstaged)
- Changes are not lost