git发明了一个叫做暂存区的概念,但是为什么要发明这个概念呢?
没有暂存区可以不?为什么一定要有暂存区?
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区的概念,比如对于branch有远程分支和本地分支,一定要分清楚。
处理冲突
你本地有改动,先提交掉,或者git stash; git pull; git stash pop
有冲突会报告both motified,处理掉之后通过git add 标记
最佳实践
- glog -33
- git config --global branch.autosetuprebase always 参考:http://www.tuicool.com/articles/NzeQZz3
- gsta && gl && gstp
常用命令
合并远程分支到本地
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参数表示创建并切换,这个命令实际上包含两部分:1.创建本地分支 2.把本地HEAD文件指向远程分支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
创建分支:git branch <name>
切换分支:git checkout <name>
创建+切换分支:git checkout -b <name>
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>
创建本地分支
git checkout -b 20160615_newant_707832
Switched to a new branch '20160615_newant_707832'指向远程分支
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出现的提示
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是推送当前分支,次问题参考http://stackoverflow.com/questions/21839651/git-what-is-the-difference-between-push-default-matching-and-simple
git原理
git远程分支 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/
问题
我本地误删了两个文件,现在要恢复应该如何恢复?(参考index区之间的关系: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
回滚之后想恢复git reflog
git rebase 冲突
解决冲突之后 git rebase --continue ,不要git ci