GitHubã«ã¯ã³ã¼ãã®æçã管çããã人ã«è¦ãããããã°ã«è²¼ä»ãããããã®ã«ä¾¿å©ãªGistã£ã¦ã®ãããã¾ãã
é常ã®ä½¿ãæ¹ã§ã¯ããã©ã¦ã¶ã§è²¼ä»ãããã¨ãããã¨æãã®ã§ãããGistãGitã®ãªã¢ã¼ããªãã¸ããªãªã®ã§ãã¯ã©ã¤ã¢ã³ããã使ãäºãåºæ¥ã¾ãã
â¦â¦ã£ã¦ã®ã¯Gistã«ãæ®éã«æ¸ãã¦ããã§ããã©ãã
Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository.
ã¨ãããããã£ã¦ã¿ã¾ãã
è²ã ãã£ã¦ã¿ã
ã¾ãé©å½ã«ä½ãã¾ãã
GitHubã¯ãéæããªãã¨ãã©ã¤ãã¼ããªãªãã¸ããªã¯ä½ããªãã®ã§ãããGistã ã¨ãã©ã¤ãã¼ãä½ããããã¾ãããã©ã¤ãã¼ãã¨è¨ãã¤ã¤ãã¢ãã¬ã¹ããã£ãã誰ã§ãã¢ã¯ã»ã¹ã§ãã¡ããç¨åº¦ã®ãã©ã¤ãã¼ãã§ããã
次ã«ãããã¯ãã¼ã³ãã¾ããã¢ãã¬ã¹ã¯ç»é¢ã«æ¸ãã¦ããã¦ãéãã
$ git clone [email protected]:644e504e9d550c2fedd3.git gist-644e504e Cloning into 'gist-644e504e'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. $ cd gist-644e504e/ $ ls -a . .. .git textfile.txt $ cat textfile.txt plain text$
ãããªãã§ããã
ãªã¢ã¼ãã¯ãµã¤ã¼ã«ãããªã£ã¦ã¾ãã
$ git remote -v origin [email protected]:644e504e9d550c2fedd3.git (fetch) origin [email protected]:644e504e9d550c2fedd3.git (push)
é©å½ã«ãã¡ã¤ã«ã追å ãã¾ãã
$ echo new> newfile.txt $ git add newfile.txt $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: newfile.txt # $ $ git commit -m'add new file' [master c8c75b2] add new file 1 file changed, 1 insertion(+) create mode 100644 newfile.txt
ã§ãpushããã
$ git push Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 271 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To [email protected]:644e504e9d550c2fedd3.git 22e7656..c8c75b2 master -> master $
ã§ãããããããã©ã¦ã¶ãæ´æ°ã
ãããããããã¼ã
ãã¨ã¯ãã©ã¦ã¶ããã®æ´æ°ã§ããããé©å½ã«å¼ã£ã¦â¦â¦rstã«å¤ãã¦ãã¾ããã
ã§ãããrstã¨ããã¡ããã¨è¡¨ç¤ºãã¦ãããã®ãç´ æµã
ã¨ã«ããåºæ¥ãã®ã§ãä½ãèããã«pullãã
$ git pull remote: Counting objects: 4, done. remote: Compressing objects: 100% (2/2), done. Unpacking objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) From gist.github.com:644e504e9d550c2fedd3 c8c75b2..9f3bf9d master -> origin/master Updating c8c75b2..9f3bf9d Fast-forward newfile.txt => newfile.rst | 1 + 1 file changed, 1 insertion(+) rename newfile.txt => newfile.rst (57%)
ç¹ã«åé¡ãªãæ´æ°ã§ãã¾ããã¼ã
ã£ã¦ãã¨ã§ããããããã¼ã«ä½¿ãã¾ãã
ã¤ã¾ãã
ãã®ã¾ã¾ãããã¾ãã«ã¤ã¾ããªãã®ã§ããã©ã¦ã¶ããåºæ¥ãªãæä½ããã¦ã¿ããããªã¨ã
æ°ãããã£ã¬ã¯ããªfugaãä½ã£ã¦ããã®ä¸ã«piyoãçªã£è¾¼ãã
$ mkdir hoge $ echo fuga>hoge/piyo.txt $ git add . $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: hoge/piyo.txt # $ git commit -m'add directory' [master 9763c29] add directory 1 file changed, 1 insertion(+) create mode 100644 hoge/piyo.txt
ã§ãpush ãã¦ãã©ã¦ã¶ãæ´æ°ã
$ git push Counting objects: 5, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (4/4), 354 bytes, done. Total 4 (delta 0), reused 0 (delta 0) To [email protected]:644e504e9d550c2fedd3.git 9f3bf9d..9763c29 master -> master
ãã¼ãã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ãã¼ãã§ã表示ã¯åºæ¥ã¦ãã£ã½ãã
ãã®ç¶æ
ã§ãã©ã¦ã¶ããç·¨éãããã©ããªãããtextfile.txtãé©å½ã«å¤ããã
â¦â¦ãªããå¢ãããå®ã¯ç·¨éãã¡ã³ã§ã hoge/piyo.txt ã hogepiyo.txt ã«ãªã£ã¦ãã
pullã£ã¦ã¿ãã
$ git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. Unpacking objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) From gist.github.com:644e504e9d550c2fedd3 9763c29..f02e038 master -> origin/master Updating 9763c29..f02e038 Fast-forward hogepiyo.txt | 1 + textfile.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 hogepiyo.txt $ ls hoge hogepiyo.txt newfile.rst textfile.txt
â¦â¦ãããæå ã§ãå¢ããã
ãã£ã¬ã¯ããªãæ¶ãã¡ããã°æ»ãã
ãã°è¦ãã¨ããã
$ git log --oneline e41f720 delete subdirectory f02e038 9763c29 add directory 9f3bf9d c8c75b2 add new file 22e7656
ãã©ã¦ã¶ããè¦ããã®ã¨åãã
å¤ãªäºãã¦ãã®ãã¬ãã¨ã¤ã¤ãªã®ã§ããµããã£ã¬ã¯ããªä½ã£ãã®ãç¡ãããã
ãã£ã¬ã¯ããªä½ãå(9f3bf9d)ã«æ»ãã¦ããã©ã¦ã¶ããã®ç·¨é(f02e038)ãcherry-pickãããæ£ç´rebaseã§ãããã ãã©ãã³ãã³ãããã®ã¾ã¾è²¼ãã®ã«åãã¦ãªãã¨æã£ãã®ã§ãã£ã¡ã
$ git reset --hard 9f3bf9d HEAD is now at 9f3bf9d $ git cherry-pick f02e038 Aborting commit due to empty commit message.
â¦â¦ã³ãããã¡ãã»ã¼ã¸ç¡ãããã£ã¦æããããæ¸ãã°ãããã§ããæ¸ãã°ã
$ git status # On branch master # Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. # # Changes to be committed: # # new file: hogepiyo.txt # modified: textfile.txt # $ git commit -m'f02e038' [master 48c2680] f02e038 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 hogepiyo.txt
ã§ããããªã¢ã¼ãã¨ã®å·®åã¨ãã°ã確èªã
$ git diff origin/master $ git log --oneline 48c2680 f02e038 9f3bf9d c8c75b2 add new file 22e7656
ããã§ããããã®ã¾ã¾pushããã¨å½ç¶ reject ããã¾ãããä»åã¯æ¹ç«ããããã -f ãã¡ããã¾ããã©ã¼ãã
$ git push -f Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (4/4), 341 bytes, done. Total 4 (delta 0), reused 0 (delta 0) To [email protected]:644e504e9d550c2fedd3.git + e41f720...48c2680 master -> master (forced update)
ã§ããã®ã§ãã©ã¦ã¶ãæ´æ°ã
ããã§ãµããã£ã¬ã¯ããªä½ã£ã¦ãäºã¯ã°ããªããããã
è足
- gistã®ã³ããããã°ã¯ç©ºã£ã½ã§ãã
- gitã¯ã³ãããã¡ãã»ã¼ã¸ã¯æ¸ããªãããããªãã®ã§ãæå ã§å¼ãã¨ãã¯æ®æ®µéãæ¸ãã
- ã§ãgistããã¯è¦ããªãã
- è¦ãããã°cloneããããï¼
- ãµããã£ã¬ã¯ããªå
¥ãã¦ãããã©ã¦ã¶ããç·¨éããªããã°åé¡ãªãã£ã½ãã
- ç°¡æãã©ã¤ãã¼ããªãã¸ããªã«ä½¿ããããããï¼
- æ£ç´å¾®å¦ã ãâ¦â¦ã¦è¨ããéæãã°ã
- bitbucketãªããã©ã¤ãã¼ãä½ãããããã
- ç°¡æãã©ã¤ãã¼ããªãã¸ããªã«ä½¿ããããããï¼
- gitãªãã§ãã©ã³ããä½ããã
- æ®éã«pushãã§ããã
- ãã©ã¦ã¶ããã¯è¦ããªããã©ã
- cloneããã°è¦ãããï¼
çµè«
å¤ãªäºãã¦ãªãã§ç´ ç´ã«GitHub使ãã¾ãããã