gitmEnE 

1. ݒ
1.1 Linux
(1)R~bg̃GfB^w
   export EDITOR=vi

1.2 Windows
(1)R}hCx[X
   msysgit
     Git-1.8.4-preview20130916.exe
	 CXg[AuGit BashvN

(2)Explorerx[X
   Tortoise git

(3)R~bg̃GfB^w
   ~/.profile
   export EDITOR=gvim

2. |Wg̏
  $ cd ~/tool    (: ~/toolǗꍇ)
  $ git init
  Initialized empty Git repository in c:/Users/oga/tool/.git/

3. t@C̒ǉ
  $ git add .
  ܂
  $ git add Makefile test.c

10. SSH J̍쐬
  SourceForgeSSH ̌JF؂𗘗pꍇAJ쐬Ao^KvB

  ɍ쐬Ă邩mF
  $HOME/.ssh/*.pub΂ꂪJ

  ȂΈȉ̃R}hō쐬B($HOME/.ssh ̉ɍ쐬)
  $ ssh-keygen
  𗘗pꍇɃpXt[YgȂꍇ̓pXt[Yŉ

  SorceForgeɃANZXꍇ[Uݒ聨uSSHJ̓o^v
  ANZXzXǧJo^B
  (o^Ăg悤ɂȂ܂Ő̂Œ)

11. SourceForgeɍ̍ƕ̃|WgɃ[J̃f[^push
  $ cd ~/tool  (your git repo)
  ---
  $ git init        (܂gitǗĂȂꍇ)
  $ git add xxx yyy ([J|Wgɒǉ)
  $ git commit      ([J|WgɕύX𔽉f)
  ---
  $ git remote add origin hyperoga@git.pf.sourceforge.jp:/gitroot/h/hy/hyperoga/ogatool.git
    (urlŎ[g|WgoriginƂ̂t)
  $ git push -u origin master  ([J|Wg(master)[g|Wg(origin)push)


{
19. {R}h
init                 : |Wg̏
clone <url>          : |Wg̕                   (svn co)
commit               : |Wgw̃R~bg             (svn commit)
push                 : [g|Wgւ̑M         (svn commit)
pull                 : [g|Wg̏C̎荞 (svn update)
diff                 : mF                           (svn diff)
status               : ԊmF                           (svn status)
add    <dir_or_file> : |WgǗΏۂɒǉ           (svn add)
branch <branch_name> : u`쐬
remote add <name> <url> : URLalias쐬(?)



http://sourceforge.jp/magazine/09/03/16/0831212
|Wg̍쐬уeiXɗpR}h
git init        |Wg쐬
git clone       ̃|Wg̕
git fsck        |Wg̐`FbNs
git gc          |Wg̕svȃIuWFNg폜AœKs

ƃc[u`𑀍EǗR}h
git status     *ύXꂽt@C\
git diff       *t@CɉꂽύX_diff`ŕ\
git add        *R~bgt@Cw肷
git commit     *ύX_R~bg
git log        *R~bgO{
git reset       ÕR~bg
git revert      ƃc[w肵R~bg_̏Ԃɂ܂Ŗ߂
git branch      u`̕\уu`̍쐬
git checkout    u`̐؂ւ
git show-branch u`̍쐬/ύX/}[W\
git merge      *[Ju`̃}[Ws
git tag        *R~bgɃ^Ot
git stash       ݂̍ƃc[̏ԂꎞIɕۊǂ
git rebase      u`̔hi㗬jύX
git mv         *OύX
git rm         *폜

ق̃|WgƂ̘AgsR}h
git pull       *ق̃|Wg̕ύX_[J|WgɃ}[W
git push       *J|WgɎ̃|Wg̓e𑗐M

20. mEnE
(1)addt@CcommitO̎
   $ git rm --cached [file_path]


|Wg̍쐬уeiXɗpR}h
{
11. R}h1Fugit initv||Wg쐬

@Git𗘗pɂ́A܂|Wg̍쐬KvB|Wg쐬sR}h́ugit initvłB|Wg쐬fBNgł̃R}hs.gitfBNg쐬AGit|Wg̊Ǘt@Cɍ쐬B

$ cd |Wg쐬fBNg
$ git init

RFGitpǗt@C

@Git̊Ǘt@C.gitfBNgɕۑB̃fBNgɂ͂܂܂ȃt@Ci[邪Aʏ킱̃t@C݂̑ӎKv͂ȂB܂A|Wg̊eݒ.git/configt@CɋL^BGitɂ͊eݒsugit configvR}hpӂĂ邪Ãt@C蓮ŕύX邱ƂłݒύX\B

commitɂ͍Œȉ̐ݒ肪Kv
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"




{
12. R}h2Fugit clonev|̃|Wg̕

@|Wg̕sɂ́uGit clonevR}h𗘗pB̃R}h͊̃|Wg烍[JɃt@CRs[čƗp̃|Wg쐬AƂꍇȂǂɗpB

$ cd |Wg쐬fBNg
$ git clone |WgURL

@|WgURL͕\1̂悤Ȍ`Ŏw肷B
\1 Gitŗpł郊|WgURL vgR 	w@
rsync 	rsync://zXg/Git|Wg̃pX
HTTP 	http://zXg[:|[gԍ]/Git|Wg̃pX
HTTPS 	https://zXg[:|[gԍ]/Git|Wg̃pX
git 	git://zXg[:|[gԍ]/Git|Wg̃pX
SSH 	ssh://[[U[@]zXg[:|[gԍ]/Git|Wg̃pX
[Jt@C 	Git|Wg̃pXfile://Git|Wg̃pX

@܂A쐬fBNgw肷邱ƂłB

$ git clone |WgURL 쐬fBNg

@git clone̓|Wg̗܂ł܂߂ă|Wg𕡐邽߁AK͂ȃvWFNg̏ꍇ͑̃t@C擾/Rs[Ȃ΂ȂȂƂBŐṼ\[Xt@C擾ړÎ݂ŎgpA\[Xt@C̏CsȂꍇ́Au--depthvIvVŎ擾郊rWw肷Ƃ悢B

@Ƃ΍ŐVrW擾ꍇAu--depth 1vƎw肷B

$ git clone --depth 1 |WgURL

{
13. R}h3Fugit fsckv||Wg̐`FbNs

@|Wgj\ꍇAugit fsckvŔjĂołB

$ git fsck

@܂ASȃ`FbNsɂ́u--fullvIvVtgit fscksB

$ git fsck --full

RFGit́udanglingIuWFNgv

@ugit fsckvł́AudanglingIuWFNgvƌĂ΂e|IuWFNgoBdanglingIuWFNg̓|WgɕύXۂɍ쐬钆ԃt@Ĉ悤Ȃ̂ŁAƂ΁ugit addvŒǉt@Cɕʂ̕ύXăR~bgꍇȂǂɎĉB̃t@C̓Xg[Weʂ̂́AcĂĂ傫ȊQ͂Ȃ߁Ač\ȂB܂Aq́ugit gcvR}hs邱ƂŁAԁiftHgł2TԁjOɍ쐬ꂽdanglingIuWFNgj邱ƂłB

{
14. R}h4Fugit gcv||Wg̕svȃIuWFNg폜AœKs

@ugit gcvR}h́A|Wg̃IuWFNg̈kipackjsvȃIuWFNg̔jȂǂŝBɂă|WggpXg[Weʂ点邾łȂAptH[}X̌҂łBpɂɎsKv͂ȂAʂ̃R~bg}[WsꍇȂǂɂ͎sƂ悢낤B

$ git gc


{
ƃc[u`𑀍EǗR}h
15. R}h5Fugit statusv|ύXꂽt@C\
16. R}h6Fugit diffv|t@CɉꂽύX_diff`ŕ\
17. R}h7Fugit addv|R~bgt@Cw肷
18. R}h8Fugit commitv|ύX_R~bg

@|WgɐVɃt@CǉAύXt@Cw肷̂ɗpR}hugit addvBǂ̃t@Cǉ/ύXꂽ̂́Augit statusvŊmFłBgit statussƁÂ̗悤ɒǉ/ύXꂽt@C̏񂪕\B

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#       modified:   HBPreferencesTransFormer.h
#       modified:   HBPreferencesTransFormer.m
#
no changes added to commit (use "git add" and/or "git commit -a")

@̃t@Cɂǂ̂悤ȕύXꂽ́ugit diffvR}hŊmFłB

$ git diff ύXmFt@C

@ύX_ۑɂ́Agit addR}hőΏۂƂt@Cw肵̂Ɂugit commitvR}hsB

$ git add ǉ/ύXt@C1 ǉ/ύXt@C2 ...
$ git commit

@܂Agit commitu-avIvVtĎsƕύXꂽt@CoăR~bgłBȀꍇVKɍ쐬ꂽt@C̓R~bgΏۂɂ͂ȂȂB

$ git commit -a

@ʏAgit commitR}hsƃGfB^NăRgbZ[W̓͂߂BGfB^NȂꍇ́u-mvIvVŃbZ[Ww肷΂悢B

$ git commit -m "R~bgbZ[W"


{
19. R}h9Fugit logv|R~bgO{

@ugit logvŃ|Wg̃R~bgO{łBR~bgO͐V̂珇ɕ\A̎ŝ悤ɂꂼ̃R~bgɂẴR~bg\nbVlƃR~bgҁA^CX^vARg\B

$ git log
commit 0b70750bdf9b02597741301c695ff46bc75036d4
Author: hoge <hoge@users.sourceforge.jp>
Date:   Thu Mar 12 19:47:31 2009 +0900

    Cleaning codes and convert TAB to space.

commit 769735fbce0a0a23a2b7547003d43518b4ec96f3
Author: hoge <hoge@users.sourceforge.jp>
Date:   Thu Mar 12 19:43:09 2009 +0900

    Cleaning code, and add comments
@F
@F

RFGit̃R~bg̓rWłȂnbVŊǗ

@CVSSubversionł̓R~bgurWvƂlŊǗ邪AGit̏ꍇR~bgnbVŊǗĂBƂΓ̃t@C̉ߋ̃o[WƔrAƂꍇAǂ̃o[W̃t@CƔr邩̓nbVŎw肷BȂAnbVŃR~bgw肷ꍇAKׂĂ͂Kv͂ȂÃR~bgӂɓł擪͂ΗǂB

@܂AR~bg̎w̓nbVłȂq́uV[gl[vƌĂ΂GCAX̂悤Ȃ̂Ŏw肷邱Ƃ\B

{
20. R}h10Fugit resetv|ÕR~bg

@R~bgɏȃ~XȂǂɋCtꍇȂǂɕ֗Ȃ̂ugit resetvBƂ΃R~bgɁugit reset --soft HEAD^vƎsƁAOɍsR~bgƂłB

$ git reset --soft HEAD^

@̏ꍇAƃc[̓e̓R~bĝ܂܂ŁuR~bgvƂƂBƃc[ɉύX_܂łꍇ́Au--softv̑Ɂu--hardvw肷΂悢A

@܂AR~bgĂéuORIG_HEADvƂOŎQƂłB𗘗pāÂ悤Ɏs邱ƂŌ݂̏ԂƃR~bgĂԂ̍\łB

$ git diff ORIG_HEAD

@CɍēxR~bgsɂ́AL̂悤ɂBsƁAɓ͂R~bgbZ[WĕҏWăR~bgsB

$ git commit -a -c ORIG_HEAD

@ȂAgit commitɁu--amendvIvVtĎs邱ƂŁAOɍsĂR~bg邱ƂłB

$ git commit
iR~bgɃ~XɋCtA~XCj
$ git commit --amend    iɍsR~bgA~XĈɒuj

@L̑́Â悤ȑƂقړ̓B

$ git commit
$ git reset --soft HEAD^    iR~bgɃ~XɋCtAR~bgj
i~XCj
$ git commit -c ORIG_HEAD

{
21. R}h11Fugit revertv|ƃc[w肵R~bg_̏Ԃɂ܂Ŗ߂

@ugit revertv͍ƃc[w肵R~bg_̏Ԃɂ܂Ŗ߂AR~bgsR}hłBɂ̓R~bgw肷nbV̓^OȂǂw肷B

$ git revert R~bg

@git revertgit resetƎĂ邪Aƃc[߂Ƃ񂪍ƗɎĉقȂ_B 



{
u`쐬/ǗR}h
22. R}h12Fugit branchv|u`̕\уu`̍쐬
23. R}h13Fugit checkoutv|u`̐؂ւ
24. R}h14Fugit show-branchv|u`̍쐬/ύX/}[W\

@݂̃\[Xc[ɐVȃu`쐬ɂ́Augit branchvgpB܂AΏۂƂu`؂ւɂ́Augit checkoutvgpB

@Ƃ΁AVɁutemp01vƂu`쐬AȌケ̃u`ōƂsɂ͎̂悤ɂB

$ git branch temp01
$ git branch
* master
  temp01
$ git checkout temp01
Switched to branch "temp01"
$ git branch
  master
* temp01

@ȂAgit checkoutɁu-bvIvVtĎsƁAVɃu`쐬Ẵu`ɐ؂ւAƂƂꔭōsBƂ΁Augit checkout -b temp01v́A2̃R}hɎsꍇƓʂɂȂB

$ git branch temp01
$ git checkout temp01

@ǂ̃u`ǂ̃u`ɍꂽAƂ́ugit show-branchvŊmFłBgit show-branchł͎̗̂悤ȏo͂sAÓu---v܂łu`Au---v㔼ŋ߂̃R~bg\ĂB

$ git show-branch
! [master] add script merging google anal.'s log and OTP's log.
 ! [temp01] Cleaning codes and convert TAB to space.
  * [temp02] Cleaning codes and convert TAB to space.
---
 +* [temp01] Cleaning codes and convert TAB to space.
 +* [temp01^] Cleaning code, and add comments
++* [master] add script merging google anal.'s log and OTP's log.

@Oł̓u`Kw\ŕ\ĂAu*vtĂs݂̍ƃu`ɂȂB܂Amn͂̕ꂼ̃R~bgPʂ\V[gl[B̗ł́Aumastervutemp01vu`쐬AɁutemp01vutemp02vu`쐬ꂽƂB


{
25. R}h15Fugit mergev|[Ju`̃}[Ws

@ugit mergev́A݂̍ƃu`ɕʂ̃u`ōsꂽύX_荞ރR}hB

$ git merge ύX_̎荞݌u`

@}[Wꍇ͂̂܂܃R~bgsBۂAt@Cɂ͉L̂悤Ȍ`ŋĂɃ}[J[ߍ܂B

<<<<<<< u`:t@C
ƒu`̓e
=======
ύX_̎荞݌i}[Wju`̓e
>>>>>>> u`:t@C

@Ƃ΁AĹumarkup.plvƂt@Cɑ΂ă}[WsAłBu<<<<<<< HEAD:markup.plvu=======v܂łƃu`markup.plɋLqĂ̂ŁAu=======vu>>>>>>> e74597cbfdb9995e540ca9e8c8a6e79705e2889c:markup.plv܂ł}[Wu`markup.plɋLqĂ̂ƂȂB

sub ulist {
    if( $l =~ m/^(Xg.*)$/ ) {
      $cap = $1;
    }

<<<<<<< HEAD:markup.pl
    print "<ul>\n";
    while( $l =~ m/^E/ ) {
      $l =~ s/^E(.*)$/<li>$1<\/li>/;
      print "foo:$l\n";
      $l = <>;
=======
    print "<p><b>$cap</b></p>\n";
    print list_start( $cap );
    while( $l = <> ) {
>>>>>>> e74597cbfdb9995e540ca9e8c8a6e79705e2889c:markup.pl
      chomp $l;
      $l =~ s/&/&amp;/g;
      $l =~ s/</&lt;/g;
      $l =~ s/>/&gt;/g;
}

@ȂꍇÃ}[J[菜ċ邩A̓}[W܂ŃR~bgsȂ̂ŒӂĂقB 


{
26. R}h16Fugit tagv|R~bgɃ^Ot

@Gitł̓R~bgnbVŊǗĂ邽߁A[U[猩Ƃǂ̕񂪂ǂ̃R~bg\Ă̂ɂBugit tagv́AÕR~bgɑ΂ĕ₷ʖi^OjtR}hB

$ git tag ^O

@^Ow肹git tagsƁÃ݂|Wgɂ^OmFłB

$ git tag rev1    iurev1vƂ^Otj
$ git tag         i^OmFj
rev1

{
27. R}h17Fugit stashv|݂̍ƃc[̏ԂꎞIɕۊǂ

@݂̍ƒ̏ԂR~bgɁAꎞIɂق̃u`ɑ΂čƂsAƂꍇɖ𗧂̂Augit stashvR}hB̃R}hł́A݂̍ƃc[̏ԂꎞIɕۑĂƂłB

$ git stash ۑ̓RgȂǁ

@git stash̎śAgit checkoutȂǂōƂu``FbNAEg΂悢BƂ̊ƒƃc[ēxĂяoɂ́Ãu``FbNAEgĂugit stash popvR}hsB܂Augit stash listvsƁAꎞۑĂƃc[ꗗ\B

$ git stash list
$ git stash pop

{
28. R}h18Fugit rebasev|u`̔hi㗬jύX

@ugit rebasev́Auu`̔hύXvƂACVSSubversionɂ͂Ȃj[Nȋ@\łBgit rebaseǂ̂悤ȏs͎̐}1QƂĂقAȒPɌ΂u`ɑ΂čsύX_AĥVrŴ̂ɓKp̂B
}1 ugit rebaseṽC[W
}1 ugit rebaseṽC[W

@}1̗̏ꍇAu`Ahu`Bɑ΂āAuύXvƁuύXvAuύXvƂ3̃R~bgsĂB܂Au`B쐬̂Au`Aɂ͕̃R~bgsĂB̂悤ȏԂŃu`Bɑ΂uget rebase u`AvsƁAu`A̍ŐVłɑ΂āAu`B쐬Ău`B̍ŐVł܂ł̊ԂɉꂽύXȉꍇύXƕύXAύXjKpAꂪu`B̍ŐVłƂȂB

@git rebase𗘗pɂ́AƂsu`Ŏ̂悤Ɏs΂悢B

$ git rebase hu`

@̂ƂAgit mergȅꍇƓlɋ_}[J[ƂƂɃt@CɋLڂB܂Augit rebase --abortvrebaseƂłB
ق̃|WgƂ̘AgsR}h

{
29. R}h19Fugit pullv|ق̃|Wg̕ύX_[J|WgɃ}[W

@ق̃|WgŉꂽύX_݂̃u`Ƀ}[Wɂ́Augit pullvR}h𗘗pB

$ git pull ύX_̎荞݌|Wg

@ύX_̎荞݌|WǵAgit clonȅꍇƓlURLŎw肷i\1jB܂Agit cloneR}hō쐬|Wg̏ꍇA.git/confiǵuremotevڂȂǂɕ|WgURLIɋL^邽߁A|Wgpullsꍇ͉L̂悤Ɏ荞݌|Wgw肵ȂƂsłB

$ git pull

()ŏCpushĂꍇgit pull͎茳̏CR~bgĂsƃ}[W (2014/06/17)


{
30. R}h20Fugit pushv|J|WgɎ̃|Wg̓e𑗐M

@git pull͂ق̃|Wg̓ẽ|WgɎ荞ނ̂AtɎ̃|Wg̓eق̃|WgiʓIɂ͌J|WgjɑMĎ荞܂R}hugit pushvłB

@git pusḧɂ́AM̃|WgURLƑMu`AMu`w肷B

$ git push M惊|Wg Mu`:Mu`

@Mu`w肵Ȃꍇ́AMu`Ɠu`w肵̂Ƃ݂ȂB܂AMu`M惊|Wgɑ݂Ȃꍇ͂̃u`쐬B

RFJ|Wgƒʏ̃|Wgbare|Wg

@GiťJ|Wg͒ʏAǗt@Ĉ݂ubare|WgvƂč쐬Bʏbare|Wgł͍ƃc[̕ύXR~bgƂ͍s킸At@ĈƂɂ̂ݎgpB܂AƂbare|WgƂĎgpfBNgɂ́u.gitvƂgqtB

@bare|WǵAu--barevIvVtĂgit inits邱Ƃō쐬łB


{
31. SVNƂ̑Ή
Subversion       Git         
------------------------------------------------------------------------------------
 checkout        clone       [g|Wg[J|WgɃRs[
                             (ߋ̕ύXׂĎ荞܂)
 commit          commit      [J|Wgcommit
                 push        [g|Wgփ[J̕ύX𔽉f
 update          pull        [g|Wg̕ύX荞
                             SVNƈႢAt@CāApullĂȂBB
 revert          checkout -- commitĂȂ݂̕ύX



{
40. guV[g   http://verytired.hateblo.jp/entry/2013/07/10/191324A
   Ƃ肠Agit statusƂߑ΍₪\݂łB

40.1
  fatal: protocol error: bad line length character: xxxx
  fatal: '/pass/to/repo.git' does not appear to be a git repository

  
    sshŃ^[~iɐڑہAbZ[Wo͂Ă\B
  ΍
    .bashrc.zshrcechoȂǂĂȉӏTĂ݂B


40.2
  fatal: '/path/to/repo.git' does not appear to be a git repository
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.

  
    git remote add |Wg̃pXԈĂ\B
  ΍
    git remote rmăpXmFāAԈĂȂaddB





40.3
  error: src refspec master does not match any.
  error: failed to push some refs to 'ssh://user@ip.ad.re.ss/pass/to/repo.git'

  
    commit̂Ȃ̂push悤ƂĂB
  ΍
    commit悤I

40.4
  error: insufficient permission for adding an object to repository database .git/objects

  
    }`AJEgaddȂǂĂČȂ
  ΍
    .giťύX

    $ sudo chmod -R 0777 .git/objects/


40.5 
  hint: Updates were rejected because the tip of your current branch is behind
  hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
  hint: before pushing again.
  hint: See the 'Note about fast-forwards' in 'git push --help' for details.

  
    pushOɍXVB

  ΍
    pullčăR~bgB


40.6 
  $ git pull
  Updating f62b387..331c050
  error: Your local changes to the following files would be overwritten by merge:
          Makefile
  Please, commit your changes or stash them before you can merge.
  Aborting
  
  
    茳(working directory)̕ύX commit  pull 悤Ƃ

  ΍
    (1)stash (ύXꎞIɉB)Ă pull 
	  (a)stash save: ݂̏ԂۑAgit ォύXӏB
         $ git stash save <Rg>
         Saved working directory and index state On master: <Rg>
         HEAD is now at 13770bf hoge
	     
	  (b)stash list: shash ̈ꗗĊmF
         $ git stash list
         stash@{0}: On master: <Rg>
      (c)pull 
         $ git pull
      (d)stash pop: 1ŉBύXӏɖ߂܂B
         $ git stash pop
         Auto-merging path/to/file
           :
         (snip)
           :
         Dropped refs/stash@{0} (fb418991e1ace34585c49007c0976a19e89f3efd)

    (2)݂̃[JύXLZĂ悢ꍇ
	   $ git checkout -- <filename>
	   ݂̏CȂɂ
	     
40.7 
$ git push         
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

  To squelch this message and adopt the new behavior now, use:

    git config --global push.default simple
    
  
    upstream̃u`݂̃u`ƈقȂꍇ
	ftHg̋(push.default)ݒwȂ
	git clone xxx  xxx.git ʖcloneꍇɔ
  ΍
    warning̒ʂC܂git̋ۂȂmatchingC݂brancĥ݈SpushȂsimpleɂ
    git config --global push.default matching
    # or
    git config --global push.default simple

      simple
        ݂̃u`upstream̃u`pushD
        upstream̃u`݂̃u`ƈقȂꍇpushȂD
        "This is the safest option and is well-suited for beginners."Ƃ̂ƁD
        ܂NȂǁCԈu`trackݒ肵Ă܂
        ƂȂǂpushłȂ̂ňS?

      matching
        git pushɓ̃u`(=}b`u`)ꂼpushD
        ܂܂ł̃ftHgD

	̑
      nothing
        pushȂD܂Kgit push origin master̂悤refsw肷KvD
      current
        ݂̃u`𓯖̃[gu`pushD
      upstream
        ݂̃u`upstream̃u`pushD

