git的基本概念

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有遠程分支和本地分支,一定要分清楚。

處理沖突
你本地有改動,先提交掉,或者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參數(shù)表示創(chuàng)建并切換,這個命令實際上包含兩部分:1.創(chuàng)建本地分支 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

創(chuàng)建分支:git branch <name>

切換分支:git checkout <name>

創(chuàng)建+切換分支:git checkout -b <name>

合并某分支到當前分支:git merge <name>

刪除分支:git branch -d <name>

  1. 創(chuàng)建本地分支
    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出現(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'.

  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/

問題
我本地誤刪了兩個文件,現(xiàn)在要恢復應該如何恢復?(參考index區(qū)之間的關系: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

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 基本概念 在本章中,我們將介紹一個分布式版本控制系統(tǒng)的設計思路,以及它與集中式版本控制系統(tǒng)的不同之處。除此之外,我...
    Gh0stClub閱讀 469評論 0 1
  • git現(xiàn)在已經(jīng)是一個程序員必須掌握的一個技能呢,最近在跟著公司項目走,公司的項目管理就是使用git,為了不在工作中...
    大喵愛讀書閱讀 363評論 0 0
  • 她是一個風箏,等待著我的抓緊,等待著放飛。我抓緊了,卻抓的太緊了,我想,在放飛一點,就一點,卻發(fā)現(xiàn)她乘風飛的卻越來...
    暮友閱讀 478評論 0 0
  • 今天有位小伙伴來說我的總結(jié)分享很棒,問我是80后還是90后(美女,你真會講話哦),哈哈聽到這個,我能不開森嗎(權當...
    桂霏是人才閱讀 1,069評論 6 1
  • 近日來杭城天氣瞬息萬變,出門時還向lulu抱怨太陽刺眼,結(jié)果不到一頓飯的功夫,已經(jīng)是狂風大作暴雨傾盆。從聽沙一路小...
    bookborn閱讀 472評論 0 0

友情鏈接更多精彩內(nèi)容