Git学习(第八天)
Feature分支:
通常添加一个新功能,我们可定不希望因为一些实验性的代码而把分支搞乱,所以每添加一个功能最好是建一个feature分支,在feature分支上面开发、实验,完成后根据需要进行合并,最后删除该featrue分支。
下面,举例一个场景:
在工作中,当我们接到一个新的功能,该功能计划于下一个开发版本中。开始准备开发。
$git checkout -b feature-car
$git add NewCarController.java $git commit -m '新车辆档案'
$git checkout dev
$git branch -d feature-car error: The branch 'feature-car' is not fully merged. If you are sure you want to delete it, run 'git branch -D feature-car'.
$git branch -D featrue-car
多人协作:
从远处仓库克隆时,实际上git自动将本地的master分支与远程的master分支对应起来了,并且远程仓库的默认名是origin。
查看远程仓库信息使用git remote 或 用查看信息更详细的 git remote -v
$ git remote GitGo $ git remote -v GitGo git@git.oschina.net:Mr.bai/GitGo.git (fetch) GitGo git@git.oschina.net:Mr.bai/GitGo.git (push)
上面显示的抓取和推送的地址,没有推送权限的就看不到push地址。
$ git push GitGo master
$ git push GitGo dev
$ git add test.txt $ git commit -m 'add Test.txt' $ git push origin dev
$ git add test.txt $ git commit -m 'add test.txt' $ git push origin dev Togithub.com:KerryPak/learngit.git ! [rejected] dev -> dev (non-fast-forward) error: failed to push some refs to 'git@github.com:KerryPak/learngit.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ 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> dev
$ git branch --set-upstream-to=origin/dev dev Branch 'dev' set up to track remote branch 'dev' from 'origin'.
$ git pull Auto-merging test.txt CONFLICT (add/add): Merge conflict in test.txt Automatic merge failed; fix conflicts and then commit the result.
$ git commit -m "fix test conflict" [dev 57c53ab] fix test conflict $ git push origin dev Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 621 bytes | 621.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0) To github.com:michaelliao/learngit.git 7a5e5dd..57c53ab dev -> dev
Rebase
$ git log --graph --pretty=oneline --abbrev-commit * d1be385 (HEAD -> master, origin/master) init hello * e5e69f1 Merge branch 'dev' |\ | * 57c53ab (origin/dev, dev) fix env conflict | |\ | | * 7a5e5dd add env | * | 7bd91f1 add new env | |/ * | 12a631b merged bug fix 101 |\ \ | * | 4c805e2 fix bug 101 |/ / * | e1e9c68 merge with no-ff |\ \ | |/ | * f52c633 add merge |/ * cf810e4 conflict fixed
$ git checkout dev $ git rebase origin
$ git log --graph --pretty=oneline --abbrev-commit * 7e61ed4 (HEAD -> master) add author * 3611cfe add comment * f005ed4 (origin/master) set exit=1 * d1be385 init hello ...
$ git push origin master
$ git rebase --continue
$ git rebase --abort