Git

SSH ํ‚ค ๋งŒ๋“ค๊ธฐ

ssh-keygen

$ ssh-keygen -t rsa -b 4096 -C "rrest@icloud.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/rrest/.ssh/id_rsa):
/Users/rrest/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/rrest/.ssh/id_rsa.
Your public key has been saved in /Users/rrest/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1iaYasPL6u/8cJY06MnhX7Z2J45cr4nz673wT8cnI20 rrest@icloud.com
The key's randomart image is:
+---[RSA 4096]----+
|                 |
|                 |
|                 |
|     . o .       |
|    o = S o      |
|   = = + o   . . |
|    @ + o o . E +|
|   + B +o=o*.+ +.|
| .o+*.o.=*B==o.  |
+----[SHA256]-----+

~/.ssh ๊ฒฝ๋กœ์— ๋‹ค์Œ ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค.

  • id_rsa
    • ๊ฐœ์ธํ‚ค (์ง€์ • ๊ฒฝ๋กœ ~/.ssh ์— ๋ณด๊ด€)
  • id_rsa.pub
    • ๊ณต๊ฐœํ‚ค (๋ณต์‚ฌํ•ด์„œ ์ €์žฅ์†Œ์— ๋„ฃ์Œ)

Parameters

  • -t
    • ์•”ํ˜ธํ™” ํƒ€์ž…
  • -b
    • ์ƒ์„ฑํ•  ํ‚ค์˜ ๋น„ํŠธ์ˆ˜ (default: 2048)
  • -C
    • ์ฃผ์„์ž…๋ ฅ

๋ฆฌ๋ฒ„ํŠธ (Revert)

Syntax

$ git revert {COMMIT_NUMBER}

CLI

๋กœ์ปฌ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ & ์ฒดํฌ์•„์›ƒ

ํ˜„์žฌ ๋ธŒ๋žœ์น˜ ๊ธฐ์ค€์œผ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

$ git checkout -b feature/CNST-001

๋กœ์ปฌ ๋ธŒ๋žœ์น˜ ์‚ญ์ œ

$ git branch -d feature/LIVEDEV-2901

์ผ๊ด„์‚ญ์ œ

$ git branch | grep 'feature' | xargs git branch -d

๋กœ์ปฌ ์ƒํƒœ ๋ณด๊ธฐ (๋ณ€๊ฒฝ ํŒŒ์ผ)

$ git status

๋กœ์ปฌ ์ž‘์—… Staged files ๋กœ ์˜ฌ๋ฆฌ๊ธฐ

$ git add file1 file2 file3 (...)
$ git add .
$ git add *

๋กœ์ปฌ ์ž‘์—… Unstaged files ๋กœ ๋‚ด๋ฆฌ๊ธฐ

$ git reset file1 file2 file3 (...)
$ git reset *
$ git reset .

๋กœ์ปฌ ์ž‘์—… ๋˜๋Œ๋ฆฌ๊ธฐ

Unstaged files ๋กœ ๋“ค์–ด ์žˆ์–ด์•ผ ํ•จ

$ git checkout file1
$ git checkout *

์ž‘์—… ์ปค๋ฐ‹ํ•˜๊ธฐ

$ git commit -m '์ž‘์—…๋‚ด์—ญ'

์ž‘์—… ํ‘ธ์‹œํžˆ๊ธฐ

$ git push

์›๊ฒฉ ๋ธŒ๋žœ์น˜ ์—…๋ฐ์ดํŠธ

์ƒˆ๋กœ ์ƒ์„ฑ๋œ ๋ธŒ๋žœ์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

$ git remote update

์›๊ฒฉ ๋ธŒ๋žœ์น˜ ์ •๋ณด ๋ฆฌ์ŠคํŠธ

$ git branch -r

์›๊ฒฉ ๋ธŒ๋žœ์น˜ ๋‹ค์šด๋กœ๋“œ & ์ฒดํฌ์•„์›ƒ

์›๊ฒฉ ๋ธŒ๋žœ์น˜๋ž‘ ๋™์ผํ•œ ์ด๋ฆ„์œผ๋กœ ์ฒดํฌ์•„์›ƒ ํ•œ๋‹ค.

$ git checkout -t origin/feature/CNST-001
$ git checkout --track origin/feature/CNST-001

๋จธ์ง€ ๋˜๋Œ๋ฆฌ๊ธฐ (Merge Commit Revert)

๋จธ์ง€ ์ปค๋ฐ‹ (Merge Commit) ์ผ๋ฐ˜์ ์ธ ๋ฆฌ๋ฒ„ํŠธ๋กœ๋Š” ๋ถˆ๊ฐ€๋Šฅ ํ•˜๋‹ค.

-m 1 ์˜ต์…˜์„ ๋„ฃ์–ด ์ค˜์•ผ ํ•œ๋‹ค.

$ git revert -m 1 {COMMIT_NUMBER}

SSH ๋“ฑ๋ก ํ›„ ์›๊ฒฉ ์ €์ •์†Œ ํ‘ธ์‹œ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ฌผ์–ด๋ณผ๋•Œ

์•„๋ž˜์™€ ๊ฐ™์ด ํ‚ค์ฒด์ธ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

$ ssh-add -K ~/.ssh/id_rsa

.gitignore ๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„๋•Œ

git ์˜ ์บ์‹œ๊ฐ€ ๋ฌธ์ œ๋˜๋Š” ๊ฒƒ์ด๋ผ ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์ „๋ถ€ ์‚ญ์ œํ›„ ์ปค๋ฐ‹ ํ•ด์•ผ ํ•œ๋‹ค.

$ git rm -r --cached .
$ git add .
$ git commit -m "fixed untracked files"

์ฐธ๊ณ ์ž๋ฃŒ

https://jojoldu.tistory.com/307?category=740343