Git & Terminal 명령어 정리

Seoyeon Kim·2022년 12월 28일

Terminal 명령어

ls : (list) 현재 자신의 위치에 존재하는 파일과 폴더를 확인하기
ls -a : 숨겨진 폴더까지 확인하기
ls -l : 폴더 상세 정보까지 출력하기

pwd : (print working directory) 현재 어떤 경로의 디렉토리에 있는지 출력하기
cd : (change directory) 경로를 이동하기
cd ~ : 사용자의 home directory로 이동하기
cd .. : 이전 경로로 돌아가기

mkdir 폴더명 : (make directory) 새로운 폴더를 생성하기
touch 파일명.확장자 : 파일을 생성하기
echo "내용" > 파일명 : 내용과 함께 새로운 파일 만들기
cat : (concatenate) 파일의 내용을 확인하기

rm : (remove) 파일을 삭제하기
rm -r : (remove -recursive) 파일을 갖고 있는 폴더를 삭제하기
rm -rf : (-force) directory 강제로 삭제
rmdir (remove directory) 비어있는 폴더를 삭제하기

cp 파일/폴더 경로/이름 : (copy) 폴더와 파일을 복사하기
mv 파일/폴더 경로/이름 : (move) 파일이나 폴더를 이동하기

history : 이전에 사용한 명령어들을 확인하기
man 명령어 : (manual) 원하는 명령어의 매뉴얼을 확인하기
clear : 터미널 비우기
q : (quit) 원래의 화면으로 나가기
: 이전에 사용했던 명령어를 불러오기

Git 명령어

git init : git 초기화
git 명령어 -h : 해당 명령어의 다양한 속성 값을 확인하는 명령어
git config --global user.name "사용자 이름" : 사용자 이름 설정
git config --global user.email "사용자 이메일" : 사용자 이메일 설정

git status : git의 상태를 확인
git add : 파일을 staging area로 이동
git add . : 모든 파일을 한 번에 staging area로 이동
git rm --cached : staging area의 파일을 working directory로 이동
git rm -r --cached . : staging area의 모든 파일을 한 번에 working directory로 이동

git commit -m "메시지" : 메시지와 함께 commit
git commit -a -m "메시지" : staging area로 이동 후 메시지와 함께 commit
git commit --amend : 최근 commit 수정

git log : commit 내역 확인
git log --oneline : commit 내역을 간단하게 확인

git show : 특정 commit 내역 확인
git diff : 다른 commit과 working directory를 비교하기
git checkout : 지정한 commit hash로 이동

git reset HEAD^ : 현재 HEAD의 이전 commit으로 되돌리기
git reset HEAD~n : 현재 HEAD부터 n 번째 이전 commit으로 되돌리기

git reset : 지정한 commit hash로 이동하고 commit을 취소
git reset --soft : head만 변경
git reset --mixed : staging area도 변경
git reset --hard : working directory와 staging area 모두 변경

git remote add origin : 원격 저장소에 연결
git remote -v : 원격 저장소와 연결이 되었는지 확인

4개의 댓글

comment-user-thumbnail
2023년 1월 26일

퍼가용

1개의 답글