본문 바로가기

Git & Github

Git & Git hub 03

Git hub에 등록 했던 branch-practice repositary를 clone해오자

 

IN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~
$ cd Documents/

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents
$ cd dev

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev
$ rm -rf branch-practice/

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev
$ ls
TIL/  first-repo/  githubvlog/  practice.md

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev
$ git clone https://github.com/JINJUN941003/branch-practice.git
Cloning into 'branch-practice'...
remote: Enumerating objects: 44, done.
remote: Counting objects: 100% (44/44), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 44 (delta 15), reused 39 (delta 13), pack-reused 0
Receiving objects: 100% (44/44), 8.36 KiB | 2.09 MiB/s, done.
Resolving deltas: 100% (15/15), done.

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev
$ ls
TIL/  branch-practice/  first-repo/  githubvlog/  practice.md

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev
$ cd branch-practice/

 

fizzfizzfizz.py 파일을 만들고 pickachu.py로 rename 해보자.

 

Worst
$ mv server.py main.py -> deleted, new file


Best
$ git mv server.py main.py -> renamed


파일의 history를 남기기 위해서는 삭제 후 생성이 아닌 이름바꾸기로 추적

 

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ touch fizzfizzfizz.py


JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git add fizzfizzfizz.py


JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git commit fizzfizzfizz.py
[main e1ce5a5] Feat : Create fizzfizzfizz.py
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 fizzfizzfizz.py


JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git push origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 285 bytes | 285.00 KiB/s, done.
Total 3 (delta 1), reused 1 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/JINJUN941003/branch-practice.git
   8b590f3..e1ce5a5  main -> main


JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git mv fizzfizzfizz.py pikachu.py


JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    fizzfizzfizz.py -> pikachu.py
        
        
        
        
JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git commit
[main dcc8166] Fix: renamed fizzfizzfizz.py to pikachu.py
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename fizzfizzfizz.py => pikachu.py (100%)



JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git push origin main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 262 bytes | 262.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/JINJUN941003/branch-practice.git
   e1ce5a5..dcc8166  main -> main

 

Undoing

 

Restore는 ctrl+Z 처럼 이전 작업을 복구한다.

아래는 pikachu.py에서 아무렇게나 입력한뒤, git restore로 복구하였다.

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ vi pikachu.py

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   pikachu.py

no changes added to commit (use "git add" and/or "git commit -a")

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ cat pikachu.py

fsfsfdsfjkdsfjsklfjs
sfdsfklds;fjsfdsf
sfdsfsk;jf4
fslfsl;kfs

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git restore pikachu.py

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ cat pikachu.py

 

Unstaging

내리다라고도 함, working directory -- git add --> staging area 로 올려놓은 내용을

다시 반대로 내리는 작업을 말한다.

 

$ git reset HEAD {filename}  으로 내일 수 잇다.

 

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   fizzbuzz.py

no changes added to commit (use "git add" and/or "git commit -a")

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git add fizzbuzz.py

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   fizzbuzz.py


JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git reset HEAD fizzbuzz.py
Unstaged changes after reset:
M       fizzbuzz.py

JIN SEONG EUN@DESKTOP-0U9MK13 MINGW64 ~/Documents/dev/branch-practice (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   fizzbuzz.py

no changes added to commit (use "git add" and/or "git commit -a")

 

 

Edit latest commit 

가장 최근이 commit을 수정하는 작업이다. 

$ git commit --amend 을 사용한다. 

 

 

Worst case: Reset

 

ex) 직전 3개의 commit을 삭제한 후, remote에 강제 push

$ git reset --hard HEAD~3
$ git push -f origin <branch>

협업 시 다른 cloned repo에 존재하던 commit log로 인해 파일이 살아나거나, 과거 이
력이 깔끔히 사라져 commit log tracking이 힘들어짐.
solution: 잘못한 이력도 commit으로 박제하고 수정한 이력을 남기자!

 

 

Best case: Revert


ex) 현재 HEAD에서 직전의 3개의 commit을 순서대로 거슬러 올라가 해당 내역에 대해
commit, push 수행

 

$ git revert --no-commit HEAD~3

$ git commit

$ git push origin <branch>

 

잘못하기 전 과거로 돌아가 최신을 유지하면서 되돌렸다는 이력을 commit으로 남겨 모
든 팀원이 이 사항을 공유하고 주지시킬 수 있음.

 

 

github issue and projects

 

Issue: 프로젝트, 레포와 관계된 모든 해야할 일과 버그, 개선사항 등을 기록
Projects: 해야할 일의 진도에 따른 구성과 우선순위 지정

 

 

 

 

 

Assignees: 이 이슈에 대한 책임인원
Labels: 이슈의 종류
Projects: 이슈를 배당할 프로젝트
Milestone: 이슈에 해당하는 중요 시점 지정

 

 

github flow with fork

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Git & Github' 카테고리의 다른 글

Git & Git hub 02  (0) 2022.08.19
Git, Github 01  (0) 2022.08.16