기타/잡동사니

깃 Git 명령어

호두밥 2021. 11. 14. 22:14

초기화

git init

내용 commit할 문서 추가하기

git add index.html

커밋

git commit -m "feat(My project refactoring)" -ammend

상태 확인

git status

commit 로그 확인

git log --oneline

새로운 branch 생성하기

git branch newBranchName

branch 목록 보기

git branch -a

branch delete 브랜치 삭제하기

git branch -d branchname

branch 이동하기 convert branch

git checkout branchName

pull

git pull

pull 실행 후 fatal: refusing to merge unrelated histories가 뜬다면 

git pull origin master  --allow-unrelated-historiess

로컬 branch 삭제 후 github에도 반영하기

git push origin --delete branchName

git commit 메세지 변경하기

git rebase HEAD~1 -i
git rebase HEAD~거슬러올라가고싶은커밋수-i
① i 를 눌러 Insert 모드 활성화
② pick as345fd commitMessage를 
③ reword as345fd newCommitMessge로 바꾼뒤
④ :wq! 후 완료
git push --force

Merge에서 confict 발생

① conflict 발생 대상 확인

git merge --continue

② 대상 확인 후 수정

③ 수정한 파일 스테이징

git add 파일경로/파일명
git add .

④ merge 실행

git merge --continue

⑤ vi가 나오면 맨 위의 merge 작업명을 수정 또는 그대로 사용

  • i를 눌러 insert 모드로 전환
  • crtl+c, :wq!로 저장