mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git branch first-branchgit
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git checkout first-branch
Switched to branch 'first-branch'服務器mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)編輯器
mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
$ git checkout -b first-branch
gitlab
mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
$ echo "Change" >> README.md.net
$ git commit -a -m 'Readme changed'
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.
[first-branch dc7b6d5] Readme changed
1 file changed, 1 insertion(+)3d
mike@win10-001 MINGW64 ~/cookbook/cookbook (first-branch)
$ git push -u origin first-branch
Counting objects: 3, done.
Writing objects: 100% (3/3), 262 bytes | 131.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for first-branch, visit:
remote: http://gitlab.aishangwei.net/root/cookbook/merge_requests/new?merge_request%5Bsource_branch%5D=first-branch
remote:
To gitlab.aishangwei.net:root/cookbook.git
* [new branch] first-branch -> first-branch
Branch 'first-branch' set up to track remote branch 'first-branch' from 'origin'.
code
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.blog
$ git merge first-branch –no-ffip
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git merge first-branch --no-ff
Merge made by the 'recursive' strategy.
README.md | 1 +
1 file changed, 1 insertion(+)開發
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git push origin master
Counting objects: 1, done.
Writing objects: 100% (1/1), 223 bytes | 223.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To gitlab.aishangwei.net:root/cookbook.git
53ec2ca..5e1ebdd master –> master
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git push origin --delete first-branch
To gitlab.aishangwei.net:root/cookbook.git
- [deleted] first-branch
當咱們長時間的運行在分支上的話,咱們有時想要同步master,能夠經過合併到master後,再切換到咱們所在的分支,Git有一個更好的方式來這個,叫作rebasing。 在rebasing中,至關於把你當前的branch分支合併到master,並同步master狀態。不過是一步完成了。
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git checkout -b rebase-branch
Switched to a new branch 'rebase-branch'
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ echo "File content" >> another_file.mdmike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git add .
warning: LF will be replaced by CRLF in another_file.md.
The file will have its original line endings in your working directory.mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git commit -m 'Another commit'
[rebase-branch c20f042] Another commit
1 file changed, 1 insertion(+)
create mode 100644 another_file.md
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
$ git push origin rebase-branch –f
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ echo "1" >> README.mdmike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git add .
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git commit -m 'Commit in master'
[master acb491e] Commit in master
1 file changed, 1 insertion(+)
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Another commit
在開發的時候可能因爲頻繁的提交信息,比較零散和片段,好比在提交多少次後,想作一個總結。這時候能夠把前面幾個合併成一個提交信息。
執行案例:
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git checkout -b squash-branch
Switched to a new branch 'squash-branch'
mike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ echo "1" >> README.mdmike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ git add .
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.mike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ git commit -a -m 'wip1'
[squash-branch 4e54db8] wip1
1 file changed, 1 insertion(+)mike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ echo "2" >> README.mdmike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ git add .
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.mike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ git commit -a -m 'wip2'
[squash-branch 5d37a65] wip2
1 file changed, 1 insertion(+)
mike@win10-001 MINGW64 ~/cookbook/cookbook (squash-branch)
$ git log --oneline
5d37a65 (HEAD -> squash-branch) wip2
4e54db8 wip1
f5f7fde (rebase-branch) Another commit
acb491e (master) Commit in master
5e1ebdd (origin/master) Merge branch 'first-branch'
dc7b6d5 (first-branch) Readme changed
53ec2ca Added readme file
$ git rebase –i HEAD~2
註解: HEAD~2 表明着咱們想擠壓最後兩個提交。假如你想要擠壓最後4個提交,那麼使用HEAD~4
原始:
改變後:
$ git rebase -i HEAD~2
[detached HEAD 48f7dae] Added two number to the readme
Date: Sun Jun 24 17:33:08 2018 +0800
1 file changed, 2 insertions(+)
Successfully rebased and updated refs/heads/squash-branch.
$ git push origin squash-branch
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (9/9), 839 bytes | 104.00 KiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for squash-branch, visit:
remote: http://gitlab.aishangwei.net/root/cookbook/merge_requests/new?merge_request%5Bsource_branch%5D=squash-branch remote: To gitlab.aishangwei.net:root/cookbook.git * [new branch] squash-branch -> squash-branch