Git 고급 명령어

2020. 1. 9. 13:06·기타/git

.gitignore

파일 형상관리시에

staging Area, Local, Remote Repository에 등록될 필요가 없는 파일을 자동으로 제외시켜주는 파일이다.

ex. Log, Backup File, Compiled File

gitignore 자동설정내역 생성페이지 를 들어가면 개발환경에 맞게 기본 설정된 gitignore 파일 내역을 출력해준다.

 

add 취소 (File Staging Cancel)

git reset "File name or Directory Name"

default: File, Directory Name 생략시 add했던 모든 파일과 디렉토리.

최근 commit 취소

git reset [option] HEAD

HEAD의 위치를 옮겨서 마지막 commit을 취소함. (HEAD는 현재 브랜치의 마지막 commit 을 의미)

♣ [option]

--soft: staging 상태 유지

--mixed: staging 상태 해제 (다시 add 해야 현재 local directory 수정 사항이 반영된다.)

--hard: staging 상태 해제 + working directory 내의 commit 당시 대상 파일이나 디렉토리 삭제

git reflog를 통해 commit 로그를 확인하고 특정 commit 시점으로 돌아간다.

마지막 Commit Message update

ex. commit -m "

!

!@#!!$!$~" 내용이 잘못되었을 경우 메시지만 수정. (Local -> Remote repository upload 파일는 그대로)

git commit --amend -m "테스트 코드 추가"

※ --amend: 직전 commit message 수정.

이전 Commit Hash log 확인. (보통 복구를 위한 사전 확인작업)

git reflog

Push 완료된 Commit 과거 버전으로 복구

git revert

지난 Commit에 대한 해시 값인 HashValue는

git reflog 를 통해 확인 가능하다.

Remote Repository 상의 파일이나 디렉토리 삭제하기

ex. 쓸데없거나 연관성 없는 파일을 실수로 같이 올린경우

 

# (1) 우선 remote repository 에서 파일 삭제
git rm --cached "파일명"
# 디렉토리 예하 모든 파일 삭제시  
git -rm --cached -r "디렉토리명"

# (2) commit message 작성
git commit -m "~~~"

# (3) 원격 저장소에 push
git push -u origin "브런치명"

 

 

[Option]

--cached: Local Repository 상에서의 File은 지우지 않음. (유지)

※ history 가 그대로 남기 때문에 민감한 파일은 이방법이 추천되지 않음 => 미리 .gitignore 파일에 명시하는 것이 중요.

remote origin URL 변경하기

git remote set-url origin git@gitlab.com:유저아이디/유저RepositoryName


Branch 이름 변경하기

git checkout <old_branch_name>
git branch -m <new_branch_name>

이미 예전 브랜치에 push한게 있다면 다음 구문을 추가 입력해야한다

git push origin -u <new_branch_name>
git push origin --delete <old_branch_name>

 

하위 Branch 생성하기

(1) 상위 branch로 이동한다.

(2) 하위 branch를 다음 명령어로 생성한다.

git checkout -b <new_branch_name> <parent_branch_name>

 

마스터 브랜치 예하의 개발 브런치 예하의 채널기능 브런치를 생성한다.

Ex) master 

           -- develop

                --feature/add-channel

branch option

* -b : 브런치 생성하면서 이동

* -m : 브런치 이름 변경 // git branch -m <old branch name> <new branch name>

git checkout master
git checkout -b dev master //master 예하의 develop 브런치 생성하고 develop 브랜치로 이동
git checkout -b feature/add-channel develop // develop 브런치 예하의 feature/add-channel  브런치 생성하고 브랜치 이동

git stash

마무리 하지 않은 작업(commit 하지 않은 불완전한 상태)을 스택에 임시 저장한다.

스택 생성 직후 working directory 는 비워진 상태가 된다.

commit 이전에 다른 branch 의 일을 수행할 때 유용하다.

 

(1) Staging Area File (add 된 파일)

(2) Tracked File (not added but committed before at least once)

 

 

stash Create

git stash
또는
git stash save

 

stash READ

stash 목록을 볼 수 있다.

git stash list

 

 

stash Update

가장 스택 최상단에 위치한 애를 현재 working, staging area, local repository 에 적용한다. (stash 상태를 그대로 복원)

git stash apply

적용과 동시에 삭제하고 싶다면 

git stash pop

 

stash DELETE

스택에 남아있는 stash 를 모두 제거한다.

git stash drop

 


원격 저장소 이름 변경

git remote rename <기존_원격저장소명> <새_원격저장소명>
# ex) git remote rename origin new_remote_repo

원격 저장소 주소 변경

git remote set-url <원격저장소명> <원격저장소_주소>
# ex) git remote set-url origin git@github.com:user/repo.git 

 

 

 


🔗 Reference 

https://parksb.github.io/article/28.html

linuxize.com/post/how-to-rename-local-and-remote-git-branch/

https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/

저작자표시 (새창열림)

'기타 > git' 카테고리의 다른 글

gitlab Setting (gitlab 시작하기, 설정)  (0) 2020.01.13
error:src refspec master does not match any 해결  (0) 2020.01.09
Git 개념 정리  (0) 2020.01.09
github push Error (non-fast-forward)  (0) 2019.11.27
Github 기본 명령어  (0) 2019.09.13
'기타/git' 카테고리의 다른 글
  • gitlab Setting (gitlab 시작하기, 설정)
  • error:src refspec master does not match any 해결
  • Git 개념 정리
  • github push Error (non-fast-forward)
M_Falcon
M_Falcon
  • M_Falcon
    Falcon
    M_Falcon
  • 전체
    오늘
    어제
    • 분류 전체보기 (432)
      • Web (16)
        • Nodejs (14)
        • Javascript (23)
        • FrontEnd (4)
      • DataBase (39)
        • Fundamental (1)
        • Redis (4)
        • PostgreSQL (10)
        • NoSQL (4)
        • MySQL (9)
        • MSSQL (3)
        • Error (4)
      • Algorithm (79)
        • Algorithm (문제풀이) (56)
        • Algorithm (이론) (23)
      • JVM (65)
        • Spring (13)
        • JPA (5)
        • Kotlin (13)
        • Java (24)
        • Error (7)
      • 기타 (70)
        • Kafka (3)
        • Kubernetes (3)
        • Docker (13)
        • git (19)
        • 잡동사니 (27)
      • 재테크 (11)
        • 세무 (4)
        • 투자 (3)
        • 보험 (0)
      • BlockChain (2)
        • BitCoin (0)
      • C (32)
        • C (10)
        • C++ (17)
        • Error (3)
      • Low Level (8)
        • OS (3)
        • 시스템 보안 (5)
      • 네트워크 (3)
      • LINUX (30)
        • Linux (26)
        • Error (4)
      • 저작권과 스마트폰의 이해 (0)
      • 생각 뭉치 (6)
      • 궁금증 (2)
      • Private (4)
        • 이직 경험 (0)
        • 꿈을 찾아서 (1)
      • Android (21)
        • OS (4)
  • 블로그 메뉴

    • 홈
    • WEB
    • 알고리즘
    • DataBase
    • Linux
    • Mobile
    • C
    • 방명록
  • 링크

    • github
  • 공지사항

  • 인기 글

  • 태그

    android
    PostgreSQL
    kafka
    Git
    백준
    알고리즘
    Kotlin
    Bitcoin
    C++
    프로그래머스
    linux
    JPA
    Spring
    docker
    javascript
    database
    Programmers
    java
    ubuntu
    algorithm
  • hELLO· Designed By정상우.v4.10.3
M_Falcon
Git 고급 명령어
상단으로

티스토리툴바