git

js·2022년 3월 29일
0
post-thumbnail

repositories 클론하기

git clone '레포지터리 주소' 
git add '변경된 파일'
git commit -m "message"
// branch 이름 main으로 변경
git branch -M main 
git push origin main 
git remote -v

local에서 repositories 연결하기

git init
git remote add origin https://github.com/{username}/{reponame}.git
touch README.md
git add README.md
git commit -m "docs: Create README.md"
git push -u origin main

커밋 메시지

docs:feat:conf:fix:refactor:ci:build:perf:
문서작업기능구현환경설정버그수정리팩토링지속적 통합빌드퍼포먼스

ex)

feat: Create server.py to start flask project
docs: Create README.md
conf: poetry init
test: User model CRUD test complete

branch와 merge

	// 확인
	git branch 
    // 삭제
    git branch -D '브랜치명'
    // 생성 
	git branch '브랜치명'
    // branch 전환 , git checkout도 같은 기능을 한다.
	git switch '브랜치명'
    // merge
    git merge '브랜치명'

서로 다른 내용의 branch들끼리 merge할 경우 merge conflict(충돌)가 일어난다.

conflict가 일어난 파일은 conflict난 log가 해당 파일의 코드에 반영되므로 꼭 수정해주자 !!!

revert

// 파일 바꾸기 
git mv '원래파일명' '변경할파일명'
// 되돌리기
git restore '파일명'
// 현재 디렉토리 전부 되돌리기
git restore . 

취소하기

// git add 취소, git revert를 권장한다 
git reset HEAD '파일명'
// git commit 취소
git reset HEAD^
// git commit 메시지 수정
git commit --amend
// 현재 HEAD에서 직전의 3개의 commit을 순서대로 거슬러 올라간다 
git revert --no-commit HEAD~3..

계정 관련

// git name, email 확인
git config user.name
git config user.email

// git name, email 변경
git config --global '이름'
git config --global '이메일'

fork한 repo 최신화 하기

git remote add upstream '팀장 repo'
git remote -v 
git pull upstream develop

기타 명령어

// git 상태 확인
git status
// 연결된 remote 확인
git remote -v
// push 에러 상황에서, 이전 commit들은 모두 삭제하고 현재 commit으로 덮어 씌운다
Git push origin '브랜치명' -- force

0개의 댓글