git發(fā)明了一個叫做暫存區(qū)的概念已亥,但是為什么要發(fā)明這個概念呢虑椎?
沒有暫存區(qū)可以不俱笛?為什么一定要有暫存區(qū)?
git 一些基本概念
http://www.atatech.org/articles/11236
http://www.worldhello.net/2010/11/30/2166.html
git checkout feature/20160705_dev_slot_735955
本地丟棄
git reset --hard HEAD
1.git 沒有trunk,萬物皆branch泥技,
2.git 比svn多了work區(qū)的概念磕仅,比如對于branch有遠(yuǎn)程分支和本地分支,一定要分清楚平夜。
處理沖突
你本地有改動卸亮,先提交掉兼贸,或者git stash; git pull; git stash pop
有沖突會報告both motified,處理掉之后通過git add 標(biāo)記
最佳實(shí)踐
- glog -33
- git config --global branch.autosetuprebase always 參考:http://www.tuicool.com/articles/NzeQZz3
- gsta && gl && gstp
常用命令
合并遠(yuǎn)程分支到本地
git merge --no-ff origin/zheliang-temp
git merge --no-ff origin/20160727_fun_to_tlive
feature/20160615_newant_707832
查看日志
git log --graph --left-right --cherry-pick --oneline
切換分支
git checkout -b remotes/origin/feature/20160615_newant_707832
git checkout命令加上-b參數(shù)表示創(chuàng)建并切換,這個命令實(shí)際上包含兩部分:1.創(chuàng)建本地分支 2.把本地HEAD文件指向遠(yuǎn)程分支remotes/origin/feature/20160615_newant_707832.
等同于下面兩個命令:
git checkout dev
git br
- master
remotes/origin/feature/20160615_newant_707832
刪除本地分支:
git br -d remotes/origin/feature/20160615_newant_707832
Deleted branch remotes/origin/feature/20160615_newant_707832 (was dc1f1ef).
Git鼓勵大量使用分支:
查看分支:git branch
創(chuàng)建分支:git branch <name>
切換分支:git checkout <name>
創(chuàng)建+切換分支:git checkout -b <name>
合并某分支到當(dāng)前分支:git merge <name>
刪除分支:git branch -d <name>
創(chuàng)建本地分支
git checkout -b 20160615_newant_707832
Switched to a new branch '20160615_newant_707832'指向遠(yuǎn)程分支
git branch --set-upstream-to=remotes/origin/feature/20160615_newant_707832 20160615_newant_707832
- 查看config
cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@gitlab.alibaba-inc.com:tmallwireless-data-driven/ant.git
fetch = +refs/heads/:refs/remotes/origin/
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
name = yunpeng.jiangyp
email = yunpeng.jiangyp@alibaba-inc.com
[branch "20160615_newant_707832"]
remote = origin
merge = refs/heads/feature/20160615_newant_707832
- 本地修改文件,commit出現(xiàn)的提示
Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit.
On branch 20160615_newant_707832
Your branch is up-to-date with 'origin/feature/20160615_newant_707832'.
- git push matching VS simple
建議使用:
git config --global push.default simple
matching是推送所有分支喧务,simple是推送當(dāng)前分支,次問題參考http://stackoverflow.com/questions/21839651/git-what-is-the-difference-between-push-default-matching-and-simple
git原理
git遠(yuǎn)程分支 https://git-scm.com/book/zh/v1/Git-%E5%88%86%E6%94%AF-%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF
https://git-scm.com/book/zh/v1/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA%E4%B8%8E%E5%90%88%E5%B9%B6
https://git-scm.com/book/zh/v1/Git-%E5%88%86%E6%94%AF-%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF
http://www.ruanyifeng.com/blog/2014/06/git_remote.html
https://higoge.github.io/2015/07/06/git-remote03/
問題
我本地誤刪了兩個文件功茴,現(xiàn)在要恢復(fù)應(yīng)該如何恢復(fù)?(參考index區(qū)之間的關(guān)系:http://www.worldhello.net/2010/11/30/2166.html)
? ant git:(feature/20160707_0706_newfix_740019) ? git st
On branch feature/20160707_0706_newfix_740019
Your branch is up-to-date with 'origin/feature/20160707_0706_newfix_740019'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml
deleted: app/src/main/webapp/META-INF/hsf/hsf-provider.xml
? ant git:(feature/20160707_0706_newfix_740019) ? git co -- app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml
error: pathspec 'app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml' did not match any file(s) known to git.
? ant git:(feature/20160707_0706_newfix_740019) ? git reset HEAD app/src/main/webapp/META-INF/hsf/hsf-provider.xml
Unstaged changes after reset:
M app/src/main/java/com/tmall/wireless/ant/web/comm/sso/LoginUserAclFilter.java
M app/src/main/java/com/tmall/wireless/ant/web/controller/AntBaseController.java
M app/src/main/java/com/tmall/wireless/ant/web/controller/AntPerformanceTestController.java
M app/src/main/java/com/tmall/wireless/ant/web/controller/AntStatusController.java
M app/src/main/resources/applicationContext.xml
M app/src/main/webapp/META-INF/biz/spring-common.xml
D app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml
D app/src/main/webapp/META-INF/hsf/hsf-provider.xml
M app/src/main/webapp/WEB-INF/web.xml
M biz/src/main/java/com/tmall/wireless/ant/biz/ant/AntSlotQueryService.java
M biz/src/main/java/com/tmall/wireless/ant/biz/ant/commons/UnionEnum.java
M biz/src/main/java/com/tmall/wireless/ant/biz/ant/impl/AntBaseQueryServiceImpl.java
M biz/src/main/java/com/tmall/wireless/ant/biz/ant/impl/AntSlotQueryServiceImpl.java
M deploy/src/ibatis-generator/generatorConfig.xml
? ant git:(feature/20160707_0706_newfix_740019) ? git co app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml
? ant git:(feature/20160707_0706_newfix_740019) ? ll app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml
-rw-r--r-- 1 jiangyunpeng staff 692B 7 13 16:11 app/src/main/webapp/META-INF/hsf/hsf-comsumer.xml
git 回滾到上一個版本
命令:git reset --hard HEAD^
參考:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000
回滾之后想恢復(fù)git reflog
git rebase 沖突
解決沖突之后 git rebase --continue ,不要git ci