git分支的合并和删除
2020-02-07Linux90root603°c
A+ A-查看当前在哪一个分支
[[email protected] yunweigit-]# git branch
* azhen
master
[[email protected] yunweigit-]# ls
999.txt lanmp.sh
合并分支(合并时一定要切换到目标分支下)
[[email protected] yunweigit-]# git checkout master Switched to branch 'master' [[email protected] yunweigit-]# git branch azhen * master [[email protected] yunweigit-]# git merge azhen Updating bedacb5..6f2009e Fast-forward 999.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 999.txt [[email protected] yunweigit-]# ls 999.txt lanmp.sh
如果master分支和aming分支都对999.txt进行了编辑,当合并时会提示冲突,需要先解决冲突才可以继续合并。 解决冲突的方法是在master分支下,编辑999.txt,改为azhen分支里面999.txt的内容。 然后提交999.txt,再合并azhen分支。 但是这样有一个问题,万一master分支更改的内容是我们想要的呢? 我们可以编辑999.txt内容,改为我们想要的,然后提交。切换到azhen分支,然后合并master分支到azhen分支即可。(倒着合并)合并分支有一个原则,那就是要把最新的分支合并到旧的分支。也就是说merge后面跟的分支名字一定是最新的分支。
建立了分之后轻易不要在master上修改配置文件,我们只做合并使用就行。如更改会发生冲突的现象,除非把冲突的内容和分支内容一致才可以提交。(不建议在master上修改)
删除分支
[[email protected] yunweigit-]# git branch azhen * master [[email protected] yunweigit-]# git branch -d azhen Deleted branch azhen (was e86c86d). [[email protected] yunweigit-]# git branch * master
如果分支没有合并,删除之前会提示,那我们就不想合并,强制删除
[[email protected] yunweigit-]# git branch -D azhen
标签:Git