Minimal Git Command Save

🌈 This is a repository that summarizes the Git commands and tips that you should at least know about development.

Project README

Minimal_Git_command

Git 을 μ‚¬μš©ν•˜λ©΄μ„œ 자주 μ‚¬μš©ν•˜λŠ” λͺ…령어듀에 λŒ€ν•΄ μ •λ¦¬ν•œ repository μž…λ‹ˆλ‹€.

Basic

add

git add [file name]

λ³€κ²½ 사항이 μžˆλŠ” λͺ¨λ“  파일 add

git add .

commit message 와 commit

git commit -m "[commit message]"

λ³€κ²½ 사항이 μžˆλŠ” λͺ¨λ“  파일 add 와 λ™μ‹œμ— commit

git commit -am "[commit message]"

remote repository λ“±λ‘ν•˜κΈ°

git remote add [remote github repository address]

νŠΉμ • branch μƒμ„±ν•˜λ©° remote 에 push ν•˜κΈ°

git push origin [branch name]

branch κ°„ μ΄λ™ν•˜κΈ°

git checkout [branch name]

branch μƒμ„±ν•˜κΈ°

git checkout -b [branch name]

branch 이름 λ°”κΎΈκΈ°

git branch -M [changed name]

이전 commit κ³Ό λΉ„κ΅ν•˜μ—¬ 파일 λ³€κ²½ 사항 ν™•μΈν•˜κΈ°

git diff

commit log 보기

git log

git log graph 둜 좜λ ₯ν•˜κΈ°

git log --graph

Useful command

λ³€κ²½ 사항이 μžˆλŠ” 파일 λ³€κ²½ 사항 μ·¨μ†Œν•˜κΈ°

git checkout -- [file name]

commit ν•œ 개 μ·¨μ†Œν•˜κΈ°

git reset HEAD^

or

git revert HEAD

λ°”λ‘œ 이전 commit message μˆ˜μ •ν•˜κΈ°

git commit --amend

local git repository 에 remote repository 을 upstream 으둜 λ“±λ‘ν•˜κΈ°

git remote add --track master upstream [remote github repository address]

master branch λ₯Ό uptream 의 latest version 으둜 update μ‹œν‚€κΈ°

git pull --ff upstream master

μ—¬λŸ¬ commit 을 ν•˜λ‚˜λ‘œ ν•©μΉ˜κΈ°(squash)

git rebase -i HEAD~[commit 개수]

.gitconfigμ—μ„œ μ„€μ •ν•΄λ‘” editor 창이 λ‚˜νƒ€λ‚œλ‹€. 기쀀이 될 맨 μœ„μ˜ ν•œ commit 만 pick으둜 두고 λ‚˜λ¨Έμ§€λŠ” squashλΌλŠ” λͺ…λ Ήμ–΄λ‘œ λ°”κΏ”μ€€λ‹€. :wq λͺ…λ Ήμ–΄λ₯Ό 톡해 μ €μž₯ν•˜κ³  μ’…λ£Œν•œλ‹€. 그러면 또 λ‹€λ₯Έ editor 창이 λ‚˜νƒ€λ‚˜λŠ”λ°, commit message λ₯Ό μ„€μ •ν•˜λŠ” editor 이닀. μ›ν•˜λŠ” commit message λ₯Ό μž…λ ₯ν•˜κ³  :wq λͺ…λ Ήμ–΄λ₯Ό 톡해 μ €μž₯ν•˜κ³  μ’…λ£Œν•΄μ£Όλ©΄ squash κ°€ λœλ‹€.

git history 좜λ ₯ν•˜κΈ°

git reflog

λ°”λ‘œ 이전 commit 에 μƒˆλ‘œμš΄ 파일 λ³€κ²½ 사항을 μΆ”κ°€ν•˜κΈ°

git commit -C HEAD --amend

cf> λ§Œμ•½ push λ₯Ό ν•œ μƒνƒœλΌλ©΄ -fμ˜΅μ…˜μ„ ν†΅ν•΄μ„œ push λ₯Ό ν•΄μ€˜μ•Ό ν•œλ‹€. commit 을 μƒˆλ‘œ μƒμ„±ν•˜μ§€ μ•Šκ³  변경사항을 μΆ”κ°€ν•˜λŠ” κ²ƒμ²˜λŸΌ λ³΄μ΄μ§€λ§Œ λ‚΄λΆ€μ μœΌλ‘œλŠ” μƒˆλ‘œμš΄ 컀밋이 μƒκΈ°λŠ” 것이기 λ•Œλ¬Έμ— push 된 commit κ³Ό λ‹€λ₯Έ commit 이닀.

파일의 λ³€κ²½ 이λ ₯을 λ¬΄μ‹œν•΄μ„œ stage μ—μ„œ μž„μ‹œλ‘œ μ œμ™Έν•˜κΈ°

git update-index --assume-unchanged [파일λͺ…]

파일의 λ³€κ²½ 이λ ₯을 λ¬΄μ‹œν•΄μ„œ stage μ—μ„œ μž„μ‹œλ‘œ μ œμ™Έν•œ 상황을 되돌리기

git update-index --no-assume-unchanged [파일λͺ…]

ν˜„μž¬ branch μ—μ„œ λ³€κ²½ 사항 컀밋없이 μ €μž₯해두기

git stash

μ €μž₯ν•΄λ‘μ—ˆλ˜ λ³€κ²½ λ‚΄μ—­ 뢈러였기

git stash pop

λ‹€λ₯Έ branch 의 νŠΉμ • commit κ°€μ Έμ™€μ„œ merge ν•˜κΈ°

git cherry-pick [COMMIT_HASH_NUMBER]

upstream μ œκ±°ν•˜κΈ°

git branch --unset-upstream

상황에 λ”°λ₯Έ git command 집합

상황 1. conflict κ°€ λ°œμƒν•˜λŠ” 상황

μ—¬λŸ¬ 가지 방법이 μžˆμ§€λ§Œ κ·Έ 쀑 두 가지.

git merge upstream/master
(resolve conflict in editor)
git add src
git commit
git rebase upstream/master
(resolve conflict in editor again)
git add src
git rebase --continue
git push -f upstream YOUR_BRANCH_NAME

or

git fetch upstream
git rebase upstream/master
(resolve conflict)
git add .
git rebase --continue
git push -f origin [YOUR_WORKING_BRANCH_NAME]

상황 2. κ³Όκ±° commit 에 fix ν•œ commit 이 μ‘΄μž¬ν•˜μ—¬ 이 commit μˆœμ„œλ₯Ό μ •λ ¬ν•˜κ³  싢은 상황

μ–΄λ–€ commit 이 이미 μ˜¬λΌκ°”λŠ”λ° κ·Έ commit 에 ν•΄λ‹Ήν•˜λŠ” μˆ˜μ • 사항이 λ°œμƒν•˜λ©΄ 그에 ν•΄λ‹Ήν•˜λŠ” fix commit 을 μΆ”κ°€ν•  κ²½μš°κ°€ μžˆλ‹€. 이 λ•Œ, commit 의 μˆœμ„œκ°€ λ‚œμž‘ν•΄μ§€λŠ”λ° 이 경우,fixupκ³Ό autosquash command λ₯Ό μ‚¬μš©ν•œλ‹€.

git commit --fixup [HASH]

μ΄λ ‡κ²Œ ν•΄μ„œ ν•΄λ‹Ή fix commit 을 좔가해놓은 λ‹€μŒμ—

git rebase -i --autosquash [HASH]

μœ„ λͺ…λ Ήμ–΄λ₯Ό ν†΅ν•΄μ„œ squash ν•΄μ£Όλ©΄ 컀밋 μˆœμ„œλ„ μ •λ ¬λ˜λ©΄μ„œ ν•˜λ‚˜μ˜ commit 으둜 squash λœλ‹€. μœ„ λͺ…λ Ήμ–΄μ—μ„œ HASHλž€ μ–΄λŠ 컀밋뢀터 squash λ₯Ό ν•  것인가λ₯Ό μ˜λ―Έν•œλ‹€.

cf> fixup 과 squash 그리고 squeeze 의 차이점
squashλŠ” μƒˆλ‘œμš΄ μΈν„°νŽ˜μ΄μŠ€κ°€ μ—΄λ¦¬λ©΄μ„œ commit message 도 μˆ˜μ •(포함 λ˜λŠ” 배제)ν•  수 μžˆλ‹€. fixup은 commit message λ₯Ό pickν•œ commit 에 λŒ€ν•΄μ„œλ§Œ μ μš©ν•œλ‹€. squeezeλŠ” squash ν•˜κ³ μž ν•˜λŠ” λͺ¨λ“  commit message λ₯Ό ν¬ν•¨ν•˜λ©΄μ„œ squash ν•œλ‹€.


μ•Œμ•„λ‘λ©΄ μ“Έλͺ¨μžˆλŠ” Git Tip

Git command alias

Git을 μ„€μΉ˜ν•œ λ””λ ‰ν† λ¦¬μ—λŠ” .gitconfig 파일이 μ‘΄μž¬ν•œλ‹€. 이 νŒŒμΌμ—μ„œ 자주 μ‚¬μš©ν•˜λŠ” λͺ…령어에 λŒ€ν•΄μ„œ alias λ₯Ό 지정해쀄 수 μžˆλ‹€.

[alias]
    g = git
    st = status
    co = checkout
    ad = add
    cm = commit -m
    acm = commit -am
    ph = push
    rb = rebase -i
    fh = fetch
    df = diff
    br = branch -a
    lg = log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) - %C(green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(yellow)%d%    C(reset)' --all
    re = reset HEAD\\^
    fu = fetch upstream
    rum = rebase upstream/master
    pom = push origin master
    list = config --get-regexp alias
    readme = !git add . && git commit -m "Update README.md" && git push origin master
    docs = !git add . && git commit -m "Update" && git push origin master
    update = !git fetch upstream && git rebase upstream/master && git push origin master

Commit Log format

  • 제λͺ©κ³Ό 본문을 빈 ν–‰μœΌλ‘œ λΆ„λ¦¬ν•œλ‹€
  • 제λͺ© 행을 50 자둜 μ œν•œν•œλ‹€
  • 제λͺ© ν–‰ 첫 κΈ€μžλŠ” λŒ€λ¬Έμžλ‘œ μ“΄λ‹€
  • 제λͺ© ν–‰ 끝에 λ§ˆμΉ¨ν‘œλ₯Ό 넣지 μ•ŠλŠ”λ‹€
  • 제λͺ© 행에 λͺ…령문을 μ‚¬μš©ν•œλ‹€
  • 본문을 72 자 λ‹¨μœ„λ‘œ κ°œν–‰ν•œλ‹€
  • μ–΄λ–»κ²Œ λ³΄λ‹€λŠ” 무엇과 μ™œλ₯Ό μ„€λͺ…ν•œλ‹€
  • 제λͺ©
    • λŒ€λ¬Έμž, λ™μ‚¬λ‘œ μ‹œμž‘. μ•žμ— 'If applied, this commit will 'κ°€ μƒλž΅λœ κ²ƒμœΌλ‘œ κ°„μ£Ό
    • 가급적 50 자 μ•ˆμͺ½
    • λ§ˆμΉ¨ν‘œ μƒλž΅
  • λ³Έλ¬Έ
    • 3 번째 쀄뢀터 μ‹œμž‘ (λ‘λ²ˆμ§Έ 쀄은 비움)
    • μ΅œλŒ€μ€„ λ„ˆλΉ„λŠ” 80 자. 이상은 μ€„λ°”κΏˆ

μΆ”μ²œ 동사(personal)

  • Add : μƒˆλ‘œμš΄ κΈ°λŠ₯ λ˜λŠ” api μΆ”κ°€
    • 예) Add API creating PDF
  • Remove : 제거
    • 예) Remove unused local variables
  • Enhance : κΈ°λŠ₯ λ˜λŠ” μ„±λŠ₯의 ν–₯상
    • 예) Enhance performance in select queries
  • Fix : 버그, μ˜€νƒ€, μŠ€νƒ€μΌμ˜ μˆ˜μ •
    • 예) Fix typos in Javadoc
    • 예) Fix styles for standards of Naver Corp
  • Upgrade : 라이브러리 버전 μ—…κ·Έλ ˆμ΄λ“œ
    • 예) Uprade commons-dbcp to 2.3.1
  • Document : λ¬Έμ„œν™”
  • Refactor : λ¦¬νŒ©ν† λ§
  • Update : λ‹€λ₯Έ μ£Όλ³€ 상황에 λ§žμΆ”μ–΄μ„œ κ°±μ‹ 
    • 예) Update README.md for 1.0 release
  • Polish : μž‘λ‹€ν•œ μˆ˜μ • 묢음 (λ‹€λ₯Έ μ μ ˆν•œ 문ꡬ가 없을 경우 μ‚¬μš©)

Reference>

Open Source Agenda is not affiliated with "Minimal Git Command" Project. README Source: JaeYeopHan/Minimal_Git_command
Stars
104
Open Issues
0
Last Commit
5 years ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating