티스토리 뷰
git
참고 및 원문사이트
[https://rogerdudler.github.io/git-guide/index.ko.html]()
[https://git-scm.com/book/ko/v1/Git%EC%9D%98-%EA%B8%B0%EC%B4%88-Git-%EC%A0%80%EC%9E%A5%EC%86%8C-%EB%A7%8C%EB%93%A4%EA%B8%B0]()
이미 사용중인 디렉토리를 GIT 저장소로 만들기
git init
: .git 이라는 하위 디렉토리 생성됨 (skeleton : 뼈대가 되는 파일)
[root@localhost public_html]# ll .git/
-rw-r--r-- 1 root root 23 11월 27 09:52 HEAD
drwxr-xr-x 2 root root 6 11월 27 09:52 branches
-rw-r--r-- 1 root root 92 11월 27 09:52 config
-rw-r--r-- 1 root root 73 11월 27 09:52 description
drwxr-xr-x 2 root root 242 11월 27 09:52 hooks
drwxr-xr-x 2 root root 21 11월 27 09:52 info
drwxr-xr-x 4 root root 30 11월 27 09:52 objects
drwxr-xr-x 4 root root 31 11월 27 09:52 refs
기존 사용하던 git 저장소가 있다면 복제 (clone) 하기
git clone 저장소경로
git clone 사용자명@호스트:저장소경로
git clone git://github.com/schacon/grit.git
: 새로운 클라이언트를 연결하고자 할때 사용 (git 저장소의 모든 history 까지 받아옴)
처음 저장소를 clone 하면 모든 파일은 tracked 이면서 Unmodified 상태

git clone origin@192.168.10.154:/home/origin/public_html
[root@localhost public_html]# git status
# On branch master
nothing to commit, working directory clean
10.154 에서 commit 되지 않은 파일은 복사되지 않음
vim kek 이라는 파일 생성후
[root@localhost public_html]# git status
\# On branch master
\# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# kek
nothing added to commit but untracked files present (use "git add" to track)
untracked file 에 kek 포함 스냅샷(커밋) 에 포함되지 않음
kek 이라는 파일 추적
[root@localhost public_html]# git add kek
[root@localhost public_html]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: kek
#
기존 git 에서 파일이 새로 생성된 경우 git add 명령어 사용 필요함
# Changes not staged for commit: (tracked 상태이지만 unstaged 상태) commit 를 해도 변경 업데이트 되지 않음
# Changes to be committed:
수정1 -> git add kek -> 수정2 -> 수정3 -> commit
: 수정1의 상태가 commit 됨
수정1 -> 수정2 -> 수정3 -> git add kek -> commit
최종단계에서 git add 무조건 들어가야 최신본으로 commit 됨
파일 무시하기
.gitignore
\*.\[oa\] : 확장자가 o 나 a 인 파일 무시
\*~
git config 설정
1./etc/gitconfig : 모든 사용자 및 저장소에 적용되는 설정
2.~/.gitconfig : 특정 사용자에게만 적용되는 설정
3..git/config : Git 디렉토리에 있고 특정 저장소에만 적용
git 은 역순으로 설정 READ
사용자 정보 (이름, 이메일주소) commit 이 한번 발생한 후에는 수정 불가능함
commit 할때 마다 사용자 정보를 이용함
git config --list
특정 key에 대한 사용값 확인
git config user.name
모든 파일을 git 에서 관리하게 하려면 아래와 같이 모든 파일을 add 해준다.
[takakocap@localhost ~\]$ git add *
git에 commit 하기
[takakocap@localhost ~\]$ git commit -m "first commit"
git 워킹 디렉토리안에 모든 파일이 스냅샷에 포함되어 있지는 않음
상태
tracked (관리대상)
- Unmodified (수정하지 않음)
- Modified (수정함)
- Staged (커밋하면 저장소에 기록되는)
Untracked (관리대상 아님)
git 원격저장소 연결git remote add origin 원격아이피
보내기git push origin master
받아오기git pull
bare 저장소
워킹디렉토리가 없는 저장소 (.git 확장자로 끝남)
디렉토리를 하나 생성하고 public_html
git clone --bare public_html my_project.git
git 파일 삭제
git rm
- tracked 된 파일을 삭제하고 실제로 워킹디렉토리에 있는 파일도 같이 삭제
실제 파일은 그대로 두고 git 에서만 삭제
git rm --cached readme.txt
ex)
git rm log/\*.log
*.log 파일 모두 삭제
git rm \*~
: ~ 로 끝나는 모든 파일 삭제
파일이름 변경
git mv a b
아래 명령어가 순차적으로 수행됨
mv a b
git rm a
git add b
로그
git log -p -10
git log 보여줌
-p 각 커밋의 diff 결과
-2 : 최근 2개까지의 결과
--word-diff : 줄단위 결과에서 단어 변경 사항 출력
git log -p -10 --word-diff
git log -U1 --word-diff
: 줄안에서 변경한 부분을 단어 단위로 표시
추가단어는 [+ +] , [- -] 는 삭제 단어
git log --stat
:히스토리 통계
git log --pretty=oneline
--pretty : 기본옵션외에 선택한 옵션을 통해 내용을 보여줌
online 커밋 옵션을 한줄로 출력
short, full, fuller : 정보를 가감하여 출력
git log --pretty=format:"%h - %an, %ar : %s"
: 나만의 포맷 결과를 정하여 보여줌 (git 버전이 바뀌더라도 포맷을 일치시킬수 있음)
%H Commit hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author e-mail
%ad Author date (format respects the --date= option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s Subject
git log --pretty=format:"%h %s" --graph
git log 옵션
-p 각 커밋에 적용된 패치를 보여준다.
--word-diff diff 결과를 단어 단위로 보여준다.
--stat 각 커밋에서 수정된 파일의 통계정보를 보여준다.
--shortstat --stat 명령의 결과 중에서 수정한 파일, 추가된 줄, 삭제된 줄만 보여준다.
--name-only 커밋 정보중에서 수정된 파일의 목록만 보여준다.
--name-status 수정된 파일의 목록을 보여줄 뿐만 아니라 파일을 추가한 것인지, 수정한 것인지, 삭제한 것인지도 보여준다.
--abbrev-commit 40자 짜리 SHA-1 체크섬을 전부 보여주는 것이 아니라 처음 몇 자만 보여준다.
--relative-date 정확한 시간을 보여주는 것이 아니라 2 주전처럼 상대적인 형식으로 보여준다.
--graph 브랜치와 머지 히스토리 정보까지 아스키 그래프로 보여준다.
--pretty 지정한 형식으로 보여준다. 이 옵션에는 oneline, short, full, fuller, format이 있다. format은 원하는 형식으로 출력하고자 할 때 사용한다.
--oneline --pretty=oneline --abbrev-commit 옵션을 함께 사용한 것과 동일하다.
git log --since=2.weeks
--author
--until
commit 수정
git commit --amend
git add 빼먹었거나
git 메세지를 잘못 적었거나
특정 파일 git add 를 빼먹었을때
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
위는 모두 하나의 커밋으로 기록됨
stage 상태에서 빼기
git status
# Changes to be committed:
(use "git reset HEAD ..." to unstage)
#
modified: 1.txt
modified: 2.txt
#
git reset HEAD 2.txt
git status
# Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
#
modified: 1.txt
git status
# Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
#
modified: 1.txt
#
1.txt 파일이 수정이 감지됨 (수정이 되었음)
수정하기 전으로 되돌리는것은
git checkout -- 1.txt
위험한 명령 --> commit 한것들은 내용을 찾을수 있으나 checkout 으로 삭제한것들은 절때 찾을수 없음
리모트 저장소 (목적 : 협업)
리모트 저장소 확인하기
[root@localhost public_html]# git remote
origin
: 저장소를 clone 한 경우 origin 이라는 저장소가 자동 저장됨
[root@localhost public_html]# git remote -v
origin origin@192.168.10.154:/home/origin/public_html (fetch)
origin origin@192.168.10.154:/home/origin/public_html (push)
git remote add [단축이름] [url]
git remote add rmtest@192.168.10.145:/home/rmtest/public_html
git fetch [단축이름]
원격 저장소에 있는것을 가져옴 & 머지하지 않음
git pull [단축이름]
원격 저장소에 있는것을 가져옴
git push origin master
origin 이라는 원격서버에 master 브랜치에 복사
리모트 저장소 정보 보기
[kek@localhost public_html]$ git remote show origin
rmtest@192.168.10.154's password:
* remote origin
Fetch URL: rmtest@192.168.10.154:/home/rmtest/public_html
Push URL: rmtest@192.168.10.154:/home/rmtest/public_html
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
[kek@localhost public_html]$ git remote rename origin test
리모트 이름 origin -> test 변경
리모트 저장소 삭제
git remote rm test
만들어진 태그 확인
git tag
git tag -l 'v1.4.2.*'
Annotated 태그
:만든 사람 이름, 이메일, 만든 날짜 정보에 포함
git tag -a v20181128 -m '20181128'
LightWeight 태그
특정 커밋에 대한 포인터
[kek@localhost public_html]$ git show v20181128
tag v20181128
Tagger: kek kek@kek.com
Date: Wed Nov 28 16:27:11 2018 +0900
20181128
commit 028f1dd8bbec2b816c3ac672e9919e0a4d4b77e3
Merge: 740046a ea09c4e
Author: kek kek@kek.com
Date: Wed Nov 28 16:19:48 2018 +0900
```
Merge branch 'master' of 192.168.10.154:/home/rmtest/public_html
```
태그에 서명하기 (GPG 개인키필요)
git tag -s v20181128 -m 'my signed 20181128 tag'
서명 확인
git show 명령어
태그검증
git tag -v [태그 이름]
커밋 히스토리
git log --pretty=oneline
이전 커밋에 태그 하기
git tag -a v1.2 -m 'version 1.2' 9fceb02
: 9fceb02 체크섬을 모두 적을 필요 없음
태그 공유 (리모트서버에 태그 전송]
git push origin [태그 이름]
리모트서버에 없는 태그를 모두 전송
git push origin --tags
3개의 파일 커밋시
-> 3개의 blob 파일, 디렉토리 구조 (트리개체) 1개, 메타데이터와 루트트리 가리키는 포인터가 있는 커밋 개체 1개)
브랜치 (커밋 사이를 이동 할 수 있는 포인터?)
기본적으로 git은 master 브랜치 만듬
커밋시 git은 마스터라는 이름을 만들어서 가장 마지막 커밋을 가르키게 함
가장 최근 커밋 정보를 가르킴
브랜치 생성
git branch testing
: 이 또한 마지막 커밋 (master) 을 가르킴
HEAD : 지금 작업하는 로컬 브랜치를 가리킴 (GIT 참고함) -> MASTER 를 가르키고 있음
[kek@localhost public_html]$ git checkout testing
Switched to branch 'testing'
: HEAD 가 testing 브랜치를 가르키게 됨
이슈발생
git checkout -b iss53
-b 옵션
$ git branch iss53
$ git checkout iss53
: iss53 브랜치 생성후 iss53 checkout
vim index.html (이슈수정)
$ git commit -a -m 'added a new footer [issue 53]'
: 수정하는 중간에 다른 브랜치로 checkout시 충돌 발생 커밋 완료후 이동
hotfix 브랜치에서 수정후 다시 master 로 머지
$ git checkout master
$ git merge hotfix
Fast forward
머지할 브랜치 hotfix 가 앞으로 진행한 커밋이기 때문에 master 가 hotfix 를 가르키게 됨
브랜치 삭제
git branch -d hotfix
git branch -D hotfix
브랜치 리스트
git branch --list
git diff 아직 staged 하기전인 파일을 비교할 수 있음
: 현재 파일과 staging Area 에 있는것을 비교
만약 staged 상태인 파일을 비교하려면
git diff --cached
git diff --staged
[root@localhost public_html]# git commit -m "2324234234"
[master afe06bb] 2324234234
2 files changed, 2 insertions(+), 2 deletions(-)
master 브랜치에 commit 하였고 체크섬은 afe06bb 임을 나타냄
[root@localhost public_html]# git commit -a -m "123123123"
[master 759b833] 123123123
1 file changed, 2 insertions(+), 1 deletion(-)
: tracked 되며 unstaged 인 파일까지 다 commit 하기 (git add 과정 SKIP)
'프로그램' 카테고리의 다른 글
max_input_vars (post 전송시 데이터 짤림) php.ini (0) | 2019.05.03 |
---|---|
YUMI (Your Universal Multiboot installer) (0) | 2019.03.05 |
git 설치 (0) | 2018.11.21 |
SOAP (Simple Object Access Protocol) (0) | 2018.08.21 |
TensorFlow (0) | 2018.07.12 |
- Total
- Today
- Yesterday
- IPSEC
- Apache
- cURL
- pptp
- softether
- ssh
- OpenVPN
- gitlab
- GeoIP
- php
- centos8
- iptables
- virtualbox
- L2TP
- 베이어다이나믹
- SSL
- ntp
- kvm
- centOS7
- mod_security
- MySQL
- yum
- 인증서
- NGINX
- WAF
- HAProxy
- 리눅스
- mariadb
- galera
- glusterfs
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |