03. git 03 - nephilim/js-git-kata GitHub Wiki

2013-01-07

  • ์ง„ํ–‰ ์š”์•ฝ

    • branch
      • ์ƒ์„ฑ: git branch ${branch-name}
      • ์‚ญ์ œ: git branch -d ${branch-name}
      • ์˜ˆ: ๋‚ด์šฉ ์ˆ˜์ • ํ›„ branch ์ด๋™
        • ๋˜๋Š” ๊ฒฝ์šฐ, ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ
    • start
      • line1/line2 >> test.txt
      • extra: line3/line4 add (with others)
    • 'detached head' state
      • (no branch) state
      • git checkout origin
        • 'line5' add (no branch)
        • 'line6' add (master)
      • git checkout -b ${branchname}
      • git graph๋กœ ํ™•์ธ
    • merge
      • git์€ merge ๊ฒฐ๊ณผ๊ฐ€ ์ƒˆ๋กœ์šด commit์œผ๋กœ ์ถ”๊ฐ€๋œ๋‹ค
      • ์‹คํŒจ์‹œ ์ƒˆ๋กœ์šด commit ์ถ”๊ฐ€ ์ง์ „์— ๋ฉˆ์ถค
      • ์ฃผ์š” ์˜ต์…˜ no-ff
    • merge ์ทจ์†Œ์— ๋Œ€ํ•œ ์ฃผ์š” ๋ฒ•์น™
      • ๋ˆ„๊ตฌ๊ฐ€์—๊ฒŒ merge ๋‹นํ•œ commit object๋Š” ์‰ฝ๊ฒŒ ์ทจ์†Œ๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค.
        • ์ƒ๋Œ€์˜ ๋‚ด์šฉ์— ์˜ํ–ฅ์„ ์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ƒ๋Œ€ ๋˜ํ•œ ์ž‘์—…์„ ํ•ด์•ผํ•œ๋‹ค.
      • ๋ˆ„๊ตฐ๊ฐ€๋ฅผ mergeํ•œ commit object๋Š” ์ทจ์†Œํ•  ์ˆ˜ ์žˆ๋‹ค.
        • ์ƒ๋Œ€์˜ ๋‚ด์šฉ์— ์˜ํ–ฅ์„ ์ค€ ๊ฑด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— merge commit์„ ์ทจ์†Œํ•˜๋ฉด ๋œ๋‹ค.
    • merge ํ›„ ์ผ๋ถ€ ๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉ ์—†์—ˆ๋˜ ์ผ๋กœ ํ•˜๊ธฐ๋Š” ๋ฐ˜๋“œ์‹œ ์˜ˆ์ œ๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค.
    • merge ํ›„ ์ถฉ๋Œ์ด ๋‚˜๋ฉด: CONFLICT
      • git status๋กœ You have unmerged paths. ๋ฉ”์‹œ์ง€ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

      • git ls-files -u

        • list conflicting blobs(3)

            > git ls-files -u contents
            100644 ee3ecd22c807354b4cea36b827e76c0285c9e401 1	contents
            100755 4c5ac21ed599a93e7523bbc62ed928c18364d9b8 2	contents
            100644 ecb08d9d0b10ee5bc16f1030da048596c90a7504 3	contents
          
      • git checkout --conflict=merge contents

          > cat contents
          <<<<<<< ours
          print "ohaio"
          =======
          print "hello"
          >>>>>>> theirs
        
    • patch
      • git format-patch -M
      • git show --pretty=email
    • rebase
      • git rebase ${target-branch}
        • git rebase --onto master server client
          • clien - server > master
          • branch ๋ช…์„ ์“ฐ๋ฉด ๋”ฐ๋ผ๊ฐ„๋‹ค.
            • git rebase --onto 1f3d63c HEAD feature-03
      • from common parent, make patch in current branch
      • apply the patch to the target branch
      • conflict? (no branch)
      • git rebase --continue
      • git rebase --interactive
      • todo: HEAD๋กœ fast-forwardingํ•˜๊ธฐ
        • git checkout master && git merge
    • cherry-pick
      • git cherry-pick ${changeset}
      • git am can be better than cherry-pick since it doesn't create a remote
    • merge vs rebase
    • git pull
      • = git fetch + git merge
      • git clone ...-cloned
        • git remote๋กœ ํ™•์ธ
      • fetch๋กœ ์—ฌ๋Ÿฌ branch ๊ฐ€์ ธ์˜ค๊ธฐ?
        • remote: cloned๋ฅผ test์— ๋“ฑ๋กํ•˜๊ณ  cloned์—์„œ ๊ฒฐ๊ณผ ๊ฐ€์ ธ์˜ค๊ธฐ
        • ์ถ”์  ๋ธŒ๋žœ์น˜ ๋งŒ๋“ค๊ธฐ
          • git checkout -b hotfix-10280 cloned/hotfix-10280
          • git clone์˜ ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ ์ถ”์  ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•ด ์คŒ
      • git pull --rebase
        • pull merge ๋Œ€์‹  rebase
    • discuss: ๊ณผ๊ฑฐ ์ด๋ ฅ ์ˆ˜์ •ํ•˜๊ธฐ
      • git commit --amend ๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Œ
      • answer? git rebase -i
  • ์‹ค์Šต

    • "์˜ค๋ž˜์ „ commit message" ์ˆ˜์ •ํ•˜๊ธฐ
    • git rebase -i