Back-End TIL/Git, Github

220916 Git/Github - 3

BEstyle 2022. 9. 16. 21:55

Renaming

$ mv revert.md reverted.md - 이름을 바꾸려고 했는데, 깃에서는 원래 파일을 지우고, 새로운 파일이 생기게된다.

$ git mv revert.md reverted.md 를 사용하면 이름이 바뀐다.

$ git commit - #Fix: Rename

 

Undo

$ git restore reverted.md - undo at the point it is commited

$ git restore . - undo all the files in the current, sub directory

 

Unstaging

git reset HEAD reverted.md - Unstaging (Before commiting)

 

Edit latest Commit

$ git commit --amend - undo recent commit

 

Revert

$ git revert --no-commit HEAD~3.. - 현재 HEAD에서 직전의 3개의 commit을 순서대로 거슬러 올라가 해당 내역에 대해 commit, push 수행 (--no-commit <- revert 할떄마다 commit이 뜨지 않게) (마지막 .. 은 순차적으로라는 뜻)

 

Revert merge commit

-m ( $git revert -m {1 or 2} {merge commit id} )

 

 


Work together

1. 팀장: organization을 만든다.

2. Issue template 생성

3. Clone 후 git flow init

4.대상파일 생성 후 origin develop으로 push

 

5. 팀원 : develop 확인 후, fork

6. 나의 repo 방문 전 내 할일 issue 등록

7. fork한 repo clone, git flow init

8. git flow feature start

9. WORKWORKWORK

10. git flow feature finish

11. push to origin develop

12. Open pull request

13. 팀장 : code review(절대 한번에 merge 하지말것)

14. 팀원 : 추가 작업 후 origin develop으로 push

15. Merge Conflict가 있다면 조직의 develop을 local로 pull하여 conflict 해결 후 add, commit, push

16. 팀장 : Merge Pull Request.

17. 두번째 팀원: 수정된 파일 pull. $ git pull/FETCH+merge upstream develop

 


Scenario 팀장, 팀원

 

- New Organization (Skip invitation)

- Create New repository

eg. fizzbuzz

- Issues - Settings - Set up Issues Template - Custom Template

-Propose changes - Commit Changes

 

$ cd Documents/Dev

$ cd fizzbuzz-team

$ git flow init

$ touch fizzbuzz.py

$ vi fizzbuzz.py -> :wq

$ python fizzbuzz.py

$ git add fizzbuzz.py

$ git commit fizzbuzz.py   Feat: Create fizzbuzz.py

$ git push -u origin develop

Settings-Collaborators and teams-Add people-Triage

 

 

 

Issue - SprintBacklog Get started

-Fork to my github repository - uncheck copy main branch only

- Go back to my github

$ cd Documents/dev

$ git clone https://~~

$ cd fizzbuzz-team

$ git flow init

$ git flow feature start fb-if-for

$ vi fizzbuzz.py -> :wq

$ git add fizzbuzz.py

$ git commit fizzbuzz.py - Feat: Print Fizz    X 3 (one per task: fizz buzz fizzbuzz)

$ git flow feature finish fb-if-for

$ git push -u origin develop

my github - Compare & Pull request - base repository 팀장:develop, head repository 팀원:develop

 

 

 

 

Pull requests - Comment - Files changed - Comment - Finish your review - Request changes - Submit review

 

 

Files changed - Check comments

Since it is still open, just work on develop git flow(develop branch)

$ git add fizzbuzz.py

$ git commit fizzbuzz.py

$ git add fizzbuzz.py

$ git commit fizzbuzz.py

$ git push origin develop - 연결되어 있어서 pull request 다시 안해도된다.

 

 

 

 

check files changed - conversation - resolve conversation  X 2

Files changed - viewed check - Review changes - Comment, Approve

Merge pull request

FINISH.

 

 

 

But if there's an update in 팀장's file and it is not up-to-date in mine, need to pull the file, merge with mine if there's not any conflict to solve.

$ git remote -v -> check for remote connection

$ git remote add upstream https://~~~~~ -> adds upstream (already has origin)

$ git pull upstream develop -> pulls (fetch & merge)

    OR

$ git fetch upstream develop

$ git merge FETCH_HEAD -> if there's conflict, need to solve it and push

 

Vice-versa

팀장 repository는 up-to-date 이지만, git clone에 반영이 안됬을때,

$ git pull origin develop