创建与合并分支
1. 创建分支
git branch name
本地创建,创建远程关联远程
方法a:
git push --set-upstream origin master
方法b:
*新分支传到远程
tiaxia@TIAXIA8 MINGW64 /c/Workspace/project/UIHouston/VPC-IDM-ADMIN (sonar_code_review)
$ git push origin sonar_code_review
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 389 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@github.houston.entsvcs.net:VPC-RnD/VPC-IDM-ADMIN.git
* [new branch] sonar_code_review -> sonar_code_review
别人此时可以看到此远程分支,并且修改之后,本地还获取不了此修改,如此时pull
tiaxia@TIAXIA8 MINGW64 /c/Workspace/project/UIHouston/VPC-IDM-ADMIN (sonar_code_review)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> sonar_code_review
如下操作修复:
tiaxia@TIAXIA8 MINGW64 /c/Workspace/project/UIHouston/VPC-IDM-ADMIN (sonar_code_review)
$ git branch --set-upstream-to=origin/sonar_code_review sonar_code_review
Branch sonar_code_review set up to track remote branch sonar_code_review from origin.
tiaxia@TIAXIA8 MINGW64 /c/Workspace/project/UIHouston/VPC-IDM-ADMIN (sonar_code_review)
$ git status
On branch sonar_code_review
Your branch and 'origin/sonar_code_review' have diverged,
and have 1 and 3 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
tiaxia@TIAXIA8 MINGW64 /c/Workspace/project/UIHouston/VPC-IDM-ADMIN (sonar_code_review)
$ git pull
Merge made by the 'recursive' strategy.
idm-admin-api/api/no_timeout_forward.js | 2 +-
idm-admin-api/api/util/authTypes.js | 4 ++--
idm-admin-app/bin/migrate.js | 1 -
idm-admin-app/npm/link.js | 3 ---
idm-admin-ui/app/home/home.controller.js | 2 +-
idm-admin-ui/app/import/base.controller.js | 3 +--
idm-admin-ui/app/import/step1.controller.js | 2 +-
.../app/organization/account/account.controller.js | 5 +----
.../organization/account/create.modal.controller.js | 8 ++++----
idm-admin-ui/app/utils/string.util.js | 20 +++++++++++++++-----
10 files changed, 26 insertions(+), 24 deletions(-)
2. 切换分支
git checkout name
3. 1+2
git checkout -b name
(git checkout -b newBranchName a9c146a09505837ec03b)
4. 合并分支
git merge name
5. 删除分支
git branch -d name
6. 查看分支
git branch
例子("feature/v1.1.1_dev"合并到"master"):
10@10-PC /e/Workshop/IDBBOND/systempreferenceserver (master)
$ git branch
feature/v1.1.1_dev
* master
10@10-PC /e/Workshop/IDBBOND/systempreferenceserver (master)
$ git merge feature/v1.1.1_dev
Updating 0000fc6..0158980
Fast-forward
.gitignore | 2 ++
SystemPreferenceServer/Requests/trader_request_handler.py | 4 ++++
2 files changed, 6 insertions(+)
10@10-PC /e/Workshop/IDBBOND/systempreferenceserver (master)
7. 把分支推到远程分支
git push origin newLocalBranch
8. 查找commit所在branch
EAD+xtian5@CNCND6040MB3 MINGW64 /c/Workshop/dev/backend/VPC-IDM-service ((d4a0f5116...))
$ git branch -r --contains ab074e159ac0926e72f72ddead12eda2aef45e5f
origin/saml_demo