Git 如何把本地分支代码合并至master主分支
Posted 在奋斗的大道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git 如何把本地分支代码合并至master主分支相关的知识,希望对你有一定的参考价值。
1、依据远程主分支创建本地个人分支:master:zzg-master
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git checkout -b zzg-master origin/master
Switched to a new branch 'zzg-master'
branch 'zzg-master' set up to track 'origin/master'.
2、本地分支拉取远程分支master 所以代码。
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git pull origin master
From github.com:zhouzhiwengang/SpringCloud-
* branch master -> FETCH_HEAD
Already up to date.
3、本地分支添加项目初始化sql 语句文件夹。
查看本地分支的文件状态信息:
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git status
On branch zzg-master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
sql/
nothing added to commit but untracked files present (use "git add" to track)
添加sql 文件夹本地暂存:
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git add sql/
暂存sql 文件提交:
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git commit -m "初始化sql"
[zzg-master ac4b488] 初始化sql
1 file changed, 13 insertions(+)
create mode 100644 "sql/\\345\\210\\235\\345\\247\\213\\345\\214\\226SQL.sql"
本地分支zzg-master 文件夹,推送远程分支zzg-master
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git push origin zzg-master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 675 bytes | 675.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'zzg-master' on GitHub by visiting:
remote: https://github.com/zhouzhiwengang/SpringCloud-/pull/new/zzg-master
remote:
To github.com:zhouzhiwengang/SpringCloud-.git
* [new branch] zzg-master -> zzg-master
4、代码合并:本地master 分支合并本地zzg-master 分支
分支切换:zzg-master -> master
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
本地分支代码合并:
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git merge zzg-master
Updating 3b3aa69..ac4b488
Fast-forward
"sql/\\345\\210\\235\\345\\247\\213\\345\\214\\226SQL.sql" | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 "sql/\\345\\210\\235\\345\\247\\213\\345\\214\\226SQL.sql"
推送远程master 分支
zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:zhouzhiwengang/SpringCloud-.git
3b3aa69..ac4b488 master -> master
效果截图:
Git 添加文件技巧:
git add 文件夹/ 添加整个文件夹及内容
git add *.文件类型 添加目录中所有此文件类型的文件
Git 放弃修改
git checkout . 放弃所有修改
git checkout -- filepathname 放弃某个文件的修改
以上是关于Git 如何把本地分支代码合并至master主分支的主要内容,如果未能解决你的问题,请参考以下文章