Giter Club home page Giter Club logo

minimal_git_command's Introduction

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>

minimal_git_command's People

Contributors

jaeyeophan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.