DevOps/Git
[Git ]git 의 3가지 트리 그리고 rm, mv, restore, reset 옵션
머지?는 병합입니다
2022. 6. 30. 15:25
개인 공부를 하며 정리한 글입니다.
틀린 부분, 수정할 부분이 있다면 언제든 피드백 환영입니다 :)
1. Working Directory
- untracked: Add 된 적 없는 파일
- tracked: Add된 적 있고 변경내역이 있는 파일
tracked 상태가 되야만 git으로 관리가 가능한 파일이 된다. 그래서 새로 추가한 파일은 반드시 add 가 필수 - git add 명령어를 통해 Staging Area로 이동
2. Staging Area
- commit을 위한 임시 보관소
- git commit 명령어로 Repository로 이동
3. Repository
- 초기에 git init를 해서 만들거나 , 참조링크
remote repository ( 여태껏 봐온 origin )에서 링크를 따와서
git remote add origin (원격 저장소 주소)로 생성한 친구이다. 참조링크 - .git directory 라고도 한다
📢 로컬에서 파일을 물리적으로 삭제 또는 이름 변경을 하면 수동으로 git add를 써서 Working Directory에서
Staging Area로 이동시켜야 하는데, 아래 명령어를 쓰면 자동으로 Staging Area까지 옮겨준다.
git add를 한번 더 치기 귀찮으면 아래 명령어로 bash 상에서 파일을 가공하자.
# 삭제
$ git rm ( 파일명 )
# 파일명 변경
$ git mv (원래 파일명) (변경할 파일명)
📢 add 와는 반대로 Staging Area에서 Working Directory로 옮기려면 restore
$ git restore --staged (파일명)
- --staged를 빼면 working directory에서도 제거
📢 Staging Area 생략하기
Staging Area는 커밋할 파일을 정리한다는 점에서 매우 유용하지만 복잡하기만 하고 필요하지 않은 때도 있다.
git commit 명령을 실행할 때 -a 옵션(add) 을 추가하면 Git은 Tracked 상태의 파일을 자동으로 Staging Area에 넣는다.
그래서 git add 명령을 실행하는 수고를 덜 수 있다.
$ 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 checkout -- <file>..." to discard changes in working directory)
modified: CONTRIBUTING.md
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a -m 'added new benchmarks'
[master 83e38c7] added new benchmarks
1 file changed, 5 insertions(+), 0 deletions(-)
reset의 세 가지 옵션
- --soft: repository에서 staging area로 이동
- --mixed (default): repository에서 working directory로 이동
- --hard: 수정사항 완전히 삭제