- Continuous Integration,Delivery,and Deployment
- Sander Rossel
- 419字
- 2021-07-02 15:42:17
Merging
Merging a branch into another branch is easy enough. First of all, make sure you are in the branch where you want to merge to. So, if you want to merge jarvis into master, make sure everything you want to merge is committed and pushed and then switch to master using git checkout master. Now, simply use merge branch-name and resolve any conflicts that occur:
git branch my-branch
git checkout my-branch
[Make some changes]
git add .
git commit -m "Some message"
[optional] git push -u origin my-branch
git checkout master
git merge my-branch
A nice option when merging is to merge but not commit automatically. This is the default behavior when you have merge conflicts. That way, you can inspect and edit your changes before committing. To do this, you can use the --no-commit flag while merging:
git merge my-branch --no-commit --no-ff
The --no-ff switch stands for no fast-forward. A fast-forward happens when your current branch is an ancestor of the branch you are trying to merge and the current branch has had no changes since you branched it. In that case, your branch is simply a continuation of your current branch. Git will now move your current commit to the last commit of the branch you are targeting.
The difference becomes clear when we do a merge of each scenario:
git branch merge-test
git checkout merge-test
[Add a file]
git add .
git commit -m "No FF commit"
git checkout master
git merge merge-test
git log --oneline -2
3d28b26 No FF commit
8bff38e HULK SMASH!!!
git checkout merge-test
[Add a file]
git add .
git commit -m "FF commit"
git checkout master
[Add a file]
git add .
git commit -m "This does the trick"
git merge merge-test
git log --oneline -5
5948c05 Merge branch 'merge-test'
b21e3f3 This does the trick
944321f FF commit
3d28b26 No FF commit
8bff38e HULK SMASH!!!
As you see, there is no extra merge commit after the first merge, but there is an extra commit message after the second merge. That is because the This does the trick commit is in the way of FF commit. This is also what happens when you try to commit while there are still changes on the server that you do not yet have locally. Git will push your changes and, at the same time, pull changes from the server and an extra merge commit will be created. As we know, the merge commit will not be automatically committed if there are any merge conflicts.
- UNIX編程藝術(shù)
- Visual C++串口通信開發(fā)入門與編程實踐
- Vue.js前端開發(fā)基礎(chǔ)與項目實戰(zhàn)
- Python網(wǎng)絡(luò)爬蟲從入門到實踐(第2版)
- MATLAB應(yīng)用與實驗教程
- Implementing Cisco Networking Solutions
- Service Mesh實戰(zhàn):基于Linkerd和Kubernetes的微服務(wù)實踐
- 零基礎(chǔ)學(xué)C語言第2版
- 3ds Max印象 電視欄目包裝動畫與特效制作
- Hacking Android
- Access數(shù)據(jù)庫應(yīng)用教程(2010版)
- Python數(shù)據(jù)科學(xué)實踐指南
- 算法超簡單:趣味游戲帶你輕松入門與實踐
- PhoneGap 3.x Mobile Application Development Hotshot
- Serverless從入門到進階:架構(gòu)、原理與實踐