git的基本概念

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 标记

最佳实践

  1. glog -33
  2. git config --global branch.autosetuprebase always 参考:http://www.tuicool.com/articles/NzeQZz3
  3. 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 branch dev 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>

  1. 创建本地分支
    git checkout -b 20160615_newant_707832
    Switched to a new branch '20160615_newant_707832'

  2. 指向远程分支
    git branch --set-upstream-to=remotes/origin/feature/20160615_newant_707832 20160615_newant_707832

  1. 查看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
  1. 本地修改文件,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'.

  1. 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

参考文章
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840038939c291467cc7c747b1810aab2fb8863508000

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 基本概念 在本章中,我们将介绍一个分布式版本控制系统的设计思路,以及它与集中式版本控制系统的不同之处。除此之外,我...
    Gh0stClub阅读 3,130评论 0 1
  • git现在已经是一个程序员必须掌握的一个技能呢,最近在跟着公司项目走,公司的项目管理就是使用git,为了不在工作中...
    大喵爱读书阅读 2,540评论 0 0
  • 她是一个风筝,等待着我的抓紧,等待着放飞。我抓紧了,却抓的太紧了,我想,在放飞一点,就一点,却发现她乘风飞的却越来...
    暮友阅读 3,126评论 0 0
  • 今天有位小伙伴来说我的总结分享很棒,问我是80后还是90后(美女,你真会讲话哦),哈哈听到这个,我能不开森吗(权当...
    桂霏是人才阅读 4,585评论 6 1
  • 近日来杭城天气瞬息万变,出门时还向lulu抱怨太阳刺眼,结果不到一顿饭的功夫,已经是狂风大作暴雨倾盆。从听沙一路小...
    bookborn阅读 3,101评论 0 0

友情链接更多精彩内容