Le wagon Prep work : git - Version controlling

Minsoo·2021년 7월 6일
0

prep works

목록 보기
3/4
post-thumbnail

☄️ Why do we need git ?

👉 Each time you change your code or etc, git allows you to track version of a project automatically.

  • When the file was modified
  • What changed
  • Why it was modified
  • Who did the change

So we need a tool (git) to ...

  • track document version
  • keeps an history of doc changes
  • foster team work.

1. Version(feature) controlling

☄️ Let's start to use git.

git init
From now on, each time you change something in a file anywhere in this folder, git will track these changes
Do not run in your home folder

☄️To save your last changes with git, follow this 3-step process

🎈 0. git init

Inform and declare "git init" to the file/ directory you will track.

🎈 1. Check: Check the files that were modified since your last commit

git staus

지금 니 상태가 어때? 라고 물어보는 것...file이 tracking되고 있는지 없는지 알 수 있음. 워킹트리 확인.

🎈 2. Add: Add the modified files you want to save

git add logo.png index.html style.css

git add {directory name, file name, .(all the file below this directory)}

명시적으로 깃을 track하라고 말해주는 것. staging area에 올림.

🎈 3. Commit: Commit the changes with a message that clearly details the changes you have made

git commit --message "added logo in homepage and set width"

git commit -am "content"

add + commit at once ! but the file already should have been tracking.

git commit

can make multiple line of commit message

👉 It has to be specific for workflow & collaboration

🎈 others

git diff

👉 see through what has changed, green part will show you the inserted code since last commit.

git log

👉 It shows the history of what you did.

git log -p

👉 It shows specific history.

git checkout gitidnumber

👉 Go back to the certain point to where the gitidnumber indicates.( You can find the idnumber to git log)

👉 2 steps process
1. Select the file to add to the commit

$git add <file _1_has_modified>
  1. Take a snapshot of what is in the stagging area.
$git commit --message "A meaningful message about this change"

.
.
.

  1. working tree : 수정한 내용 버전으로 만들어지기 전 단계. / 수정한 파일들
git status
  1. staging area : 수정한 내용중 커밋하고싶은 것을 스테이지에 올린다. 예) 버전 생성 시 파일이 10개 중 2개만 선택적으로 버전으로 만들고 싶을 때... 그 2개의 버전을 올린다. / 버전을 만들려고하는 파일들
git add
  1. Repository : staging area 위에 있는 2개 파일만 모아서, 하나의 리파지토리로 저장. 커밋을 하면 변경사항들이 저장된다. + 버전 생성 / 만들어진 버전
git commit

☄️ git Reset

git reset --hard gitidnumber
git reset --soft gitidnumber

👉 Reset to (go back to) the "gitidnumber" version. It does not mean you are going to delete "gitidnumber"

☄️ git Revert + conflict

when you want to go back to previous version from current version, you need to revert "current version"

👉 ex ) 1,2,3,4 버전이 있는데....
👉 제일 최근 버전(4)을 리버트하면 기존 커밋은 내버려두고, 그 커밋은 살아있다(그 커밋에서의 변화를 취소한 것이기 때문에...) 제일 최근 이전의 버전(3)이 된다.

👉 그럼 2를 리버트하면 1이 될까? - NO => 충돌 발생
👉 revert 4 > revert 3 > revert2 하면 1이 된다...
👉 반드시 역순으로 하나씩 리버트한다.

🎈.gitignore

👉 나혼자보기위한 파일, 자동으로 생기는 파일 버전관리 안하고 싶은 파일은 .gitignore파일 안에 원하는 파일명 적어서 깃 트랙 안되게 관리 가능

깃을 통해 과거를 되돌아 볼 수 있다는것이 깃의 핵심적인 효용. 차이점을 정교하게 비교하여 정확한 의사결정을 내리고 현재 상황을 신속하게 파악하는데에 도움이 된다.

sources
https://backlog.com/git-tutorial/kr/stepup/stepup1_1.html
https://opentutorials.org/course/3839

profile
Hello all 👋🏻 📍London

0개의 댓글