SlideShare a Scribd company logo
Git
2011   3   9
       (id:hiratara)
•         (id:hiratara)

•
•     Perl

      Python Java Haskell

•   Git
• Git
•
•
•
hoge.git/
hoge/.git/         bare            config
 config                             refs
 refs                              ...
 ...



             dir    hoge/                     dir
                     .gitignore
                     hoge.txt
             dir     ...
Git
Git

•
• Linus
•
Git
.git/
• .git/config
   git config



• .git/refs/...
モデルから知るGit
Author: hiratara
Date: 2/25 13:43:42

typo



index.html
images/flower.gif
css/index.css
js/index.js
•
    (               )

•              2

•       (   root)

•
•

•
    =
        index.html
    =
                     flower.gif   index.js
git   svn

SVN




Git
        A   B     C   D
git   svn
                  git merge --squash


SVN




Git
git      svn
• git
 • git   ID

     →

 •
     →
git
•

•
    →

•             ID
remotes/origin/master
tags/0.9973            heads/topic



                          heads/master
=refs/heads

•                  ref       .git/refs

    • .git/refs/tags/
    • .git/refs/heads/
    • .git/refs/remotes/
ref
• .git/
• .git/refs/
• .git/refs/tags/
• .git/refs/heads/
• .git/refs/remotes/
ref
•          2

    heads/hiratara/master
    remotes/hiratara/master
• hiratara/master
• remotes/hiratara/master
topic   master
git commit(1)
topic

        1



            master
git commit(2)
    topic

1           2



            master
topic

1           2



            master
git merge
    topic

1           2



                master
git commit(3)
    topic

1           2



                    master
                3
topic
    topic

1           2



                        master
                    3
git commit(4)
    topic

1   2       4



                    master
                3
ID
•
          ID
    →ID

•              ID

    →               ID
    →ID
ID   SHA1
     •
	    	    	 
                                	 
                                	 
                                	 
                                	 

     •                     ID
•         ID

    →ID

    →

• Git
topic

B           C



            master
       A
git rebase

B       C               B C

        master        topic
    A       B’   C’
topic

B           C



            master
       A
git cherry-pick B
     topic

 B           C



                      master
        A        B'
git cherry-pick C
     topic

 B           C



                           master
        A        B'   C'
master
A   B   C
rebase -i HEAD~3
                  master
   A'   B'   C'




   A    B    C




             A B C
reflog
          •
          • git reflog show master                           C
             master
master
A'   B'   C'




A    B    C
git reset C

A'   B'   C'




               master
A    B    C
master
A   B   C
git revert A


                    master
A   B   C      -A
topic   master
commit
topic




        master
git merge master
   topic




     master
モデルから知るGit
3
.git
                       topic
                       master

       A   B   C   D




       D                        D
•
    •
•       staged   cached
.git
                       topic
                       master

       A   B   C   D




       D                        D’
git add
.git
                           topic
                           master

        A   B    C     D



                 add
       D’                           D’
.git
                        topic
                        master

        A   B   C   D




       D’                        D’’
git add
.git
                            topic
                            master

        A    B    C     D



                  add
       D’’                           D’’
git commit
.git
                            topic
                                     master

         A      B   C   D     D’’

       commit


        D’’                         D’’
• D’
    →

•
3
.git
                              topic
                              master

         A      B   C     D
                                 commit -a
       commit                    commit filename

                    add
        D’                             D’’
(1)
.git
                            topic
                   master
       A   B   C       D




       D                            D
git checkout master
.git
                            topic
                   master
       A   B   C       D




       C                            C
(2)
.git
                             topic
                    master
        A   B   C       D




       D'                            D''
git checkout master .
.git
                            topic
                   master
       A   B   C       D




       C                            C
git checkout .
.git
                             topic
                    master
        A   B   C       D




       D'                            D'
(1)
.git
                             topic
                    master
        A   B   C       D




       C'                            C''
git reset --soft topic
.git
                              topic
                              master

        A       B   C     D




       C'                              C''
git reset topic
.git
                         topic
                         master

       A   B    C    D




       D                          C''
git reset --hard topic
.git
                        topic
                        master

       A   B   C    D




       D                         D
モデルから知るGit
•
    (origin/master                          )

•                    git fetch   git push
git@github.com:him/hoge.git

 A      B     C      D master


~/git-repos/hoge

 A      B     C     X master
git remote add
github => git@github.com:him/hoge.git

 A      B     C      D master


                         git remote add github git@...
~/git-repos/hoge

 A      B     C      X master
git fetch
github => git@github.com:him/hoge.git

 A      B     C      D master

                            git fetch github
~/git-repos/hoge            (   git remote update)

                    D github/master

 A      B     C     X master
refspec
•
• push, fetch
  (fetch                               )
github
heads/from      git fetch github from:to
heads/to        ※       heads

heads/to        git push github from:to
heads/from
fetch       refspec

• git remote add

•
merge rebase
github => git@github.com:him/hoge.git

 A      B     C      D master


~/git-repos/hoge             git rebase github/master

                    D github/master

 A      B     C     X      X` master
git push
github => git@github.com:him/hoge.git

 A      B     C      D       X` master


~/git-repos/hoge                    git push github

                    D github/master

 A      B     C     X      X` master
push              refspec
• refspec
  →"                        push"

• push.default
  nothing, matching, tracking, current
• remote.<name>.push
  (F/W           fetch                   )
fetch         pull       push(1)
github => git@github.com:him/hoge.git
heads/master
heads/another
                         git fetch github
~/git-repos/hoge         remote.<name>.fetch
remotes/github/master
remotes/github/another
heads/master
heads/local-branch
heads/another
fetch         pull         push(2)
github => git@github.com:him/hoge.git
heads/master
heads/another            branch.<name>.remote

~/git-repos/hoge                git pull = fetch + merge
remotes/github/master
remotes/github/another        branch.<name>.merge
heads/master
heads/local-branch
heads/another
fetch         pull         push(3)
github => git@github.com:him/hoge.git
heads/master
heads/another
                         git push github
~/git-repos/hoge         push.default=matching
remotes/github/master
remotes/github/another
heads/master
heads/local-branch
heads/another
github
origin/topic1   master

origin/master
                         topic1   master
hanako taro clone
origin/topic1   master

origin/master
                         topic1   master




origin/topic1

origin/master
hanako topic2
origin/topic1     master

origin/master
                           topic1   master




origin/topic1   topic2

origin/master
hanako taro fork
origin/topic1     master

origin/master
                           topic1   master




origin/topic1   topic2

origin/master
                           topic1   master
git remote -f add
origin/topic1      master

 origin/master
                             topic1   master




hanako/topic1
 origin/topic1   topic2
hanako/master
 origin/master
                             topic1   master
git push hanako topic2
origin/topic1      master

 origin/master
                                            topic1   master




hanako/topic1
 origin/topic1   topic2     hanako/topic2
                                                         topic2
hanako/master
 origin/master
                                            topic1   master
tarou pull-req
origin/topic1      master

 origin/master
                                            topic1   master




                                                          pull request
hanako/topic1
 origin/topic1   topic2     hanako/topic2
                                                         topic2
hanako/master
 origin/master
                                            topic1   master
taro remote add
hanako/topic1    master   hanako/topic2
 origin/topic1
hanako/master
 origin/master
                                          topic1   master




hanako/topic1
 origin/topic1   topic2   hanako/topic2
                                                       topic2
hanako/master
 origin/master
                                          topic1   master
merge hanako/topic2
hanako/topic1    master   hanako/topic2
 origin/topic1
hanako/master
 origin/master
                                          topic1   master




hanako/topic1
 origin/topic1   topic2   hanako/topic2
                                                       topic2
hanako/master
 origin/master
                                          topic1   master
git push origin master
hanako/topic1    master   hanako/topic2
 origin/topic1
hanako/master             origin/master               master
 origin/master
                                          topic1




hanako/topic1
 origin/topic1   topic2   hanako/topic2
                                                       topic2
hanako/master
 origin/master
                                          topic1   master
github
• git         svn


    →

•       git

More Related Content

モデルから知るGit