[신세계I&C KDT][Git] #43 Github (0614)

박현아·2024년 7월 1일
0

신세계아이앤씨 KDT

목록 보기
47/56

1. 환경설정

https://git-scm.com/download/win

2. 사용자 설정 (owner)

inky4832@daum.net (owner)
inky4833@gmail.com ( collaborator)

git config --global user.name "inky4832"
git config --global user.email "inky4832@daum.net"

위 정보는 C:\Users\ssginc76\의 .gitconfig 에 저장됨

3. 로컬저장소 생성 버전 관리 기본 1

1) 디렉토리 생성

c:\git_study

2) git_study 경로가 가서

git init <=== 로컬저장소로 만듬. .git 폴더가 생김.이곳에 버전들이 저장됨.

3) 저장소 상태 확인

git status

On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)

위 결과는 다음과 같다

  • 현재 브랜치는 main
  • 아직 커밋할 파일이 없다

4) 파일 작성 ( hello.txt )

  • hello1 입력

  • git status

On branch main
No commits ye
Untracked files:
(use "git add < file>..." to include in what will be committed)
hello.txt
hello.txt.bak

nothing added to commit but untracked files present (use "git add" to track)

위 결과는 다음과 같다.

  • 현재 브랜치는 main
  • Untracked files 는 한번도 버전관리자 되지 않은 파일 의미. 즉 git 추적해본적이 없는 파일.

5) 추적 파일 등록

git add 파일명
git add 파일명 파일명2 ....
git add sub/파일명
git add .

  • git add hello.txt

git status

Changes to be committed:
(use "git rm --cached < file>..." to unstage)
new file: hello.txt

위 결과는 다음과 같다.

  • hello.txt 파일의 변경 사항을 추적하겠다. 따라서 commit 하자. 의미.

6) 버전 생성

git commit -m "커밋메시지"

git commit -m "first commit"

git status

On branch main
nothing to commit,~

위 결과는 다음과 같다.

  • 더 이상 관리할 파일이 없다.

7) 내용수정하고 add 하고 commit

  • hello2 추가
  • git add hello.txt
  • git commit -m "second commit"

8) 버전 확인

git log
git reflog

9) 내용수정하고 add 하고 commit

  • hello3 추가

  • add + commit 한번에
    git commit -am "third commit"

4. 불필요한 파일 및 폴더 제거

https://www.toptal.com/developers/gitignore

.gitignore 파일 작성

*.bak
.gitignore

5. git의 저장 구조

작업 트리---git add---스테이지---git commit---저장소

git init한
git_study 폴더

git diff 비교 : 작업 트리와 저장소 비교
git diff --staged 비교 : 작업 트리와 스테이지 비교

6. 작업 되돌리기 ( 롤백 기능 )

1) 작업트리 되돌리기

  • git_rollback 폴더작성

    • git init

    • hello.txt 파일 생성

    • hello1 저장

    • git add hello.txt
      git commit -m "first commit"

    • hello2 저장 <== 이 작업을 취소할 예정임.

    • 되돌리기
      git restore hello.txt

      이후 hello.txt 파일에 hello1 만 남음.

2) 스테이지 되돌리기

  • 현재상태확인

    • hello2 저장

    • git status
      On branch 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: hello.txt

    • git add hello.txt

    • git status
      On branch main
      Changes to be committed:
      (use "git restore --staged < file>..." to unstage)
      modified: hello.txt

    • 스테이지 되돌리기
      git restore --staged hello.txt

    • git status
      On branch 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: hello.txt

3) 저장소 되돌리기 (최종 commit 된 버전 되돌리기)

  • hello2 추가

    • git commit -am "second commit"

    • hello3 추가

    • git commit -am "third commit"

git reset --hard 해시값

7. 브랜치 작업

1) 브랜치 보기

git branch

2) 브랜치 생성

git branch <브랜치명>

예> git branch hotfix

3) 브랜치 변경

git checkout <브랜치명>

예> git checkout hotfix

4) 브랜치 병합

  • 반드시 main에서 병합처리 한다.

    git merge <브랜치명>

    예> git merge hotfix

0개의 댓글