git merge 使用
merge 是站在你想要合并到的分支,然后merge你想要合并的分支。
1设创建了一个文件夹study_git5
mkdir study_git5
cd study_git5
2 初始化文件夹并创建一个README并commit
git init
echo "HELLO" > README
git add .
git commit -m "add README from master"
git branch list
git status
3 创建分支b1并修改README,进行commit
git checkout -b b1
echo "hello add by b1" >> README
git add .
git commit -m "b1"
4 切换到master并将b1的修改merge到master
git checkout master
git merge b1
结果:
[user_name@id study_git5]$ git init
Initialized empty Git repository in /study_git5/.git/
[user_name@id study_git5]$ echo "HELLO" > README
[user_name@id study_git5]$ git add .
[user_name@id study_git5]$ git commit -m "add README from master"
[master (root-commit) a55be9b] add README from master
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README
[user_name@id study_git5]$ git br
* master
[user_name@id study_git5]$ git st
# On branch master
nothing to commit (working directory clean)
[user_name@id study_git5]$ git checkout -b b1
Switched to a new branch 'b1'
[user_name@id study_git5]$ echo "hello add by b1" >> README
[user_name@id study_git5]$ git commit -m "b1"
[b1 c945584] b1
1 files changed, 1 insertions(+), 0 deletions(-)
[user_name@id study_git5]$ git checkout master
Switched to branch 'master'
[user_name@id study_git5]$ git merge b1
Updating a55be9b..c945584
Fast-forward
README | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
[user_name@id study_git5]$ git br
b1
* master
[user_name@id study_git5]$ cat README
HELLO
hello add by b1