Git ãå°ãã§ãé«éãå®å ¨ã«ä½¿ãæ¹æ³ãç´¹ä»
ã¯ã¦ããçºãã¦ããããªãã Git ã®è¨äºãããºã£ã¦ãã®ã§ã便ä¹ã㦠Git ã®è©±ãæ¸ãã¦ã¿ãã
- Oh, shit, git! http://ohshitgit.com/
- ãOh shit, git!ããç°¡åã«å訳ãã¦ã¿ãã(追è¨ãã) - Qiita https://qiita.com/KaminoHiroki/items/391fb421e94e82c00128
åºç¤ç¥è
git-reset ã¯å±ãªã
git reset --hard
ã¯ä½æ¥ãã£ã¬ã¯ããªã«ã³ããããã¦ããªãå¤æ´ããã£ãå ´åãå
¨ã¦ãå¹ãé£ã°ãã¦ãã¾ãå¯è½æ§ãããã¾ãã
使ãåã«å¿
ã git status
ãå®è¡ãã¦ãä½æ¥ãã£ã¬ã¯ããªã®ç¶æ
ã確èªãããæ¹ãè¯ãã§ãã
git-checkout ã¯é ã
checkout ã³ãã³ãã¯ä½æ¥ãã£ã¬ã¯ããªã®ç¶æ ãå¤æ´ãã¾ãããã®ã¨ã ãã¡ã¤ã«ã¢ã¯ã»ã¹ãçºçããããé ã ã§ãã
git-branch -f ã¯éãã¦ä¾¿å©
git branch -f
ã¯åãååã®ãã©ã³ãããã£ã¦ãç¡çãããã©ã³ããä½æã§ããã³ãã³ãã§ãã
git-reset
ã¨ç°ãªããä»»æã®ãã©ã³ããå¼ããããé常ã«å¼·åã§ãã
å°ãã§ãé«éãå®å ¨ã«ä½¿ãäºä¾ã®ç´¹ä»
åºç¤ç¥èãç´¹ä»ããã¨ããã§ãããã¤ãäºä¾ãç´¹ä»ãã¾ãã
ééã£ã¦master ãã©ã³ãã§ä½æ¥ãã¦ãã¾ã£ãã¨ã
ããç´¹ä»ãããæ¹æ³ã¯ä¸è¨ã®ã³ãã³ããã¡ãªã¿ã« @
㯠HEAD
ã¨åãã§ãã
$ git branch new-branch $ git reset --hard @~ $ git checkout new-branch
ãã®ã³ãã³ãã ã¨2ã¤åé¡ãããã
reset --hard
ã§æªã³ãããã®å 容ãå¹ãé£ã¶å±éºæ§- checkout ã使ã£ã¦ãã¦é ã
å°ãã ãæ¹åããã³ãã³ãã¯ä¸è¨ã®éãã
$ git checkout -b new-branch $ git branch -f master @~
ãããªã checkout ã®ãã¡ã¤ã«ã¢ã¯ã»ã¹ãæå°ã§ãæªã³ãããã®å 容ããã£ã¦ãæ¶ãã¾ããã
master ãã©ã³ãããªã¢ã¼ãã«è¿½å¾ããã
ããããæ¹æ³ã¯ãã¡ãã
$ git checkout master $ git pull origin
checkout ãã¦ãã©ã³ã移åããã¨ä½æ¥ãæ¢ã¾ããããã¡ã¤ã«ã¢ã¯ã»ã¹ããã£ã¦å¾®å¦ã§ãããã
ãã㧠branch -f
ã§ããã
$ git fetch origin $ git branch -f master origin/master
ã©ããªã« master 㨠origin/master ãé¢ãã¦ãã¦ãä¸ç¬ã§å®è¡ãçµããã¾ãã
ããå®å ¨ã« master ãã©ã³ãããªã¢ã¼ãã«è¿½å¾ããã
branch -f
ã reset --hard
ã¯æãã£ã¦äººã«ãªã¹ã¹ã¡ã®ã³ãã³ããããã¾ãã rebase
ã§ãã
$ git fetch origin $ git rebase origin/master master
ãããªãã³ããããã¦ããªãå¤æ´ãããã° rebase
ãå®è¡ã§ãã¾ããããã³ã³ããªã¯ããèµ·ããã git rebase --abort
ã§å
ã®ç¶æ
ã«æ»ããã¨ãã§ãã¾ãã
ãã©ã³ããã辿ããªãã³ããããæ¢ãæ¹æ³
git reflog
ã使ãã°ãã ããããªãã¨ããªãã¾ããï¼ä½¿ãæ¹ã¯é©å½ã«ã°ã°ã£ã¦ï¼
ãã¨ã git reflog show <branch_name>
ã§ãã©ã³ãã®å±¥æ´ã表示ã§ããã®ã§ããã git branch -f
ã§ãã¹ã£ã¦ãç°¡åã«æ»ãã¾ãã
ãã©ã³ãã reflog ã§è¾¿ããªããªãã¸ã§ã¯ããæ¢ã
git fsck --lost-found
ã®ä½¿ãæ¹ã¯æããã°ã«æ¸ãã¦ããã®ã§ããããåèã«é å¼µã£ã¦æ¢ãã¾ãããã
git add
ãããã¦ããã°ãã®ãªã®ãªãªãã¨ããªãã git add
ããã¦ããªãä½æ¥ã¯è«¦ãã¦ã
ã¾ã¨ã
git branch -f
ã¯éããããã¹ã£ã¦ã git reflog show <branch_name>
ã§ç°¡åã«å¾©æ§ã§ããã®ã§ãã¿ããªä½¿ãã¾ãããï¼