반응형
1. 원격 저장소 연결
--원격 저장소를 원격 저장소에 연결하기
--현재 원격 저장소에는 main 브랜치만 default로 있는 상태
$ git remote add origin https://github.com/[repository]
--원격 저장소에 모든 파일 업로드 하기
$git push --set-upstream origin master
더 간단한방법은 -u 옵션을 사용한다. 같은 역할
$git push -u origin master
(master라는 뉴 브랜치 생성됨.)
--remote와 loca의 브랜치를 묶어주는 -u 옵션 실행 후 확인 하는 법
$git branch-vv
2. 원격 저장소 브랜치 관리
--원격에 있으나 로컬에서 안보이는 main 브랜치 보이게 하기
$git fetch --all
--new branch인 main이 로컬에 생성되었다는 결과 메세지가 나온다.
--head 포인터를 특정 브랜치에 지정하고 싶은 경우
$git remote set-head origin some_branch
3. commit 취소 reset 되돌리기 revert
--1)커밋 취소
$git reset --hard [commit id]
--hard를 안하면
-->Unstaged changes after reset:
--가 뜬다.
--2)과거 커밋 내역 삭제
$git reset HEAD^
--3)discard untracked chanes
$git reset --hard
--> HEAD is now at 90f80a7 버전7입니다.
$git reset --mixed
--4) 커밋한 아이디의 정보보기
$git cat-file -p [commit id]
- git revert requires the id of the commit you want to remove, keeping it into your history
- git reset requires the commit you want to keep, and will consequentially remove anything after that from history
3-2. checkout : 변환된 파일 되돌리기
reset 수정했던 작업물 삭제
--1) 작업 트리에서 수정한 파일 되돌리기
$git checkout -- [file name]
--2) 스테이징 되돌리기
$git add [file name]
$git reset HEAD [file name] 혹은
$git restore --staged [file name]
--3) 최신 커밋 되돌리기
$git reset HEAD^
--soft HEAD^ 최근 커밋을 하기 전 상태로 작업 트리를 되돌림
--mixed HEAD^ 최근 커밋과 스테이징을 하기 전 상태로 작업 트리를 되돌림. 옵션 없을경우 default
--hard HEAD^ 최근 커밋과 스테이징, 파일 수정을 하기전 상퇴로 되돌림.
$git reset HEAD~n
n개의 커밋 되돌리기
4) 특정 커밋으로 되돌리기
$git reset [commit hash]
-- 특정A 커밋 이후에 만들었던 커밋을 삭제하고 특정A 커밋으로 이동하겠다는 의미
$git reset --hard [commit hash]
--특정 커밋 이후의 모든 작업물들은 모두 사라짐.
3-3. revert - 커밋을 되돌리더라도 최소한 커밋을 남겨둘 때
4. 한 컴퓨터에서 여러개의 계정을 사용할 때 .gitconfig 파일 설정
--config 파일 확인
$vim ~/.gitconfig
--회사에서 개인 계정을 사용할 경우 개인 계정 용도로 쓸 디렉토리 지정 후 config파일 수정
[user]
email = dev@my-company.com
name = company-id
[includeIf "gitdir:~/devhealer/"]
path = .gitconfig-personal
[user]
email = personal-id@gmail.com
name = myname-devhealer
[github]
user = github아이디
5. git branch
-- git remote branch 삭제
방법1)
git push origin --delete feature/[remote branch name]
방법2)
$git branch -d [remote branch name]
$git push origin [remote branch name]
참조 사이트
반응형
'백엔드, 기타 > Git' 카테고리의 다른 글
[Github] 깃허브 커밋 날짜 바꾸기. 깜빡하고 잔디를 못 심은 날. git rebase (0) | 2022.07.28 |
---|---|
[Git] config user.name과 user.email 삭제 하기/ 등록하기 (0) | 2020.08.27 |