반응형
  • git branch 개념
    • branch: 어떤 한commit을 가리키는 40글자의 SHA-1 체크섬 파일, 결국 branch도 어떤 특정한 commit임
    • master: 기본 branch
    • origin: 기본 remote, remote repository를 여러개 사용할 수 있고 각각의 이름을 지정해서 쓸수도 있으나 사실 이렇게 여러개 remote사용하는 경우가 별로 없음, 그래서 그냥 remote = origin이라고 쉽게 생각하면 됨, origin하면 내 local의 것이 아니라 remote 외부서버 것이라는 의미로 볼 수 있음
  • .git
    • .git/HEAD: 현재 branch
    • .git/refs/heads/*: 로컬 저장소의 branches
    • .git/refs/remotes/*: 원격 저장소의 branches
    • .git/refs/tags/*: 태그, 로컬? 원격?
  • 참고정보

commit 관련

git add <file1> <file2>
git add .
git reset HEAD <file>
git reset HEAD
git checkout -- <file>
git checkout -f <other branch>
아마 git checkout -f <other branch>로 가능할듯git clean -f
로컬저장소의 index(staging area)에 파일 2개 추가
변경된 모든 파일 추가
특정파일 add 취소 (staging area에서 내쫓기)
전체파일 add 취소 (add 취소해도 modified 상태로 남기 때문에 수정한게 없어지지 않음)
add하기 전에 수정한 것 자체를 삭제 (완전히 없어짐)
한꺼번에 모든수정자체를 없앰 (강제로 다른곳으로 가면됨)
기존파일은 이렇게 없어지는데 새로 추가한 파일, 즉 untracked까지 몽땅 없애는 방법은?
git commit <file>
git commit
git commit -a  
git commit -a -m "log" 
git commit --amend

로컬저장소의 head에 변경내용 확정
add된 전체사항 commit
add와 commit을 한꺼번에
add와 commit을 한꺼번에 하는데 commit message "log"로 지정
이전 commit에 묻어가기, commit message만 변경할때에도 사용

git reset HEAD^
(=git reset --mixed HEAD^)
 
git reset HEAD~2
git reset --soft HEAD^
git reset --mixed HEAD^
git reset --hard HEAD^
commit취소 (=Local Repository의 최신 commit 리비전을 바로전 리비전(HEAD^)로 설정) 그럼 이미 커밋한 revision번호는 어디로?
c90f6405920652b379bbfcb8a925940f2c73743f [TVOQAISSUE-8953] delete FB.init 취소했음 이 revision은 어디로?
삭제 후 바로 git show 하니까 정보는 다 나옴


commit 2개 취소
index 보존(add한 상태, staged 상태, 변경사항 당근 보존)
index 취소(add하기 전 상태, unstaged 상태, 변경사항 보존) (기본 옵션)
index 취소(add하기 전 상태, unstaged 상태, 변경사항 삭제) 워킹 디렉터리의 파일 삭제. 즉 모두 취소


 
(1)
git reset HEAD^


git reflog 또는 git log -g
git reset HEAD@{#} 또는 git reset [commit id]
(2) git commit -m "message"
(3) git push origin <branch name> -f 또는 git push origin +<branch name>
git push 취소방법 https://gmlwjd9405.github.io/2018/05/25/git-add-cancle.html
(1) commit 을 되돌림
commit 1개 취소된 상태로
Reflog(branch와 HEAD가 지난 몇달 동안에 가리켰던 commit) 확인
특정 commit 상태로


(2) 되돌려진 상태에서 다시 commit
(3) 원격저장소에 강제 push
  • git log --oneline -10
  • git log --oneline submissions/1
  • git log -5 --decorate --graph –oneline
  • git log -5 --author=dhrim –oneline
  • git log --before={3.weeks.ago} --after={2010-04-18}
  • git log --grep=“some message”
  • git log --pretty=format:"%h,%ar,%an : %s" 
  • git log --pretty=format:"%h,%ar,%an : %s" --graph
  • 1줄씩 최근 10개 commit보여줌
  • 최근 5개의 리비전을 그래프로 보여준다
  • 저자가 dhrim인 리비전을 5개 보여준다
  • 주어진 기간내의 리비전만 보여준다
  • commit 메시지에 “some message”가 포함된 것만 보여준다
  • commit 정보를 한줄 단위로 보여주되. format 에 맞게 보여줌 
  • Git GUI 툴처럼 graph로 보여줌
    • %h : commit 번호(간략) 
    • %ar : 시간 (housrs ago, days ago) 
    • %an : commit한 사람 
    • %s : commit 로그

git init: 새로운 저장소 만들기

git clone: 이미 만들어진 저장소 받아오기 (=svn checkin?)

git diff (=git diff HEAD)

git diff HEAD^

git diff 브랜치명 브랜치명: 2 브랜치간 차이

git diff 브랜치명 revision: 브랜치와 revision간 차이

git help stash (=man git-stash) stash 도움말보기

git mv: 파일명 변경

git rm: 파일삭제

branch 관련 명령

git branch
git branch -r
git branch -a
git branch -vv
local에 있는 전체 branch list랑 현재 작업중인 branch가 뭔지를 알려줌
remote에 있는 전체 branch list
remote, local에 있는 모든 branch list와 현재 작업중인 branch가 뭔지를 알려줌
현재 local branch와 remote branch가 어떤 상태에 있는지 (더 앞서있는지, 뒤에있는지 등) 알려줌
git checkout -b [branch name]
git checkout -b [branch name] revision번호
git checkout -b [생성할 local branch name] [remote branch name]
git checkout [remote branch name]
git checkout -t [remote branch name]
git push origin [생성한 branch name]
git push --set-upstream origin frontend
새로운 브랜치 생성하고 그곳으로 감
새로운 브랜치 생성하고 그곳에 특정revision(다른 branch에서 생성한 revision)을 내려받고 그곳으로 감
 
remote에 있는 특정 branch 내려받는데 local에서 이름을 바꿔서 받기
-b가 어떤 약자인지 확인해 봤으나 ( https://git-scm.com/docs/git-checkout ) branch란 의미외에 다른 약어는 없는듯



remote에 있는 특정 branch 임시로 내려받기, 소스 수정가능하나 comit/push는 안되며 타 branch로 checkout 하면 소스사라짐
remote에 있는 특정 branch 내려받기
생성한 branch를 remote로 push
To push the current branch and set the remote as upstream
git branch --set-upstream-to=origin/<branch> dev.sy branch 생성하고 push해도 remote와 local이 연결되지 않을 수 있는데 (There is no tracking information for the current branch) 그럴 때 If you wish to set tracking information for this branch you can do so with:
tracking(연결)하지 않고 다른 branch 내용 받아오고 싶을 때 (tracking안되면 'git pull' 뒤에 branch 명시해야함) Please specify which branch you want to merge with. See git-pull(1) for details.
git branch --delete [branch name]
git branch -D [branch name]
git push origin :[branch name]
local branch 삭제 (삭제할 branch로 checkout된 상태이면 안됨)
local branch 강제삭제(작업내역이나 commit이력이 있을 때 삭제안될때 있음)(삭제할 branch로 checkout된 상태이면 안됨)
삭제한 branch를 push, 즉 remote branch 삭제, origin(한칸안띄우면 안됨):[branch name]
git push origin --delete [branch] checkout 필요없이 그냥 한방에 remote branch삭제
git merge 브랜치명 현재 내가 있는 브랜치에서 브랜치명의 브랜치 내용을 가져와서 merge (checkout해서 간 다음 끌어당겨온다고 생각)
git remote
git remote -v
git remote add <remote> <url>
git fetch <remote>
git push <remote> <branch>
git remote show origin
현재 프로젝트에 등록된 리모트 저장소 확인, 저장소를 Clone 하면 `origin`이라는 리모트 저장소가 자동으로 등록
리모트 저장소, URL 확인
기존 워킹 디렉토리에 새 리모트 저장소 추가
리모트 저장소에서 데이터 가져오기
리모트 저장소로 push
리모트 저장소의 구체적인 정보 확인

 

git checkout <remote에 없는 branch name> 하면 local에 새 branch만들어지고 그전에 있던 branch내용을 그대로 가져와서 만들어짐, 그전에 commit한 이력도 그대로 다 가져오는 듯

git stash 

  • $ git diff  (1)
  • # Changed …. : ….
  • $ git stash  (2)
  • $ git diff  (3)
  • $ git pull  (4)
  • $ git stash pop  (5)
  • $ git commit –a –m “my modification”  (6)
  • (1) 변경된 사항이 있다.
  • ......
  • (2) 변경된 사항을 Stash에 보관해 두고, 현재의 상태를 Local Repository의 최근 commimt 상태로 변경한다.
  • (3) 변경된 사항이 없음을 확인
  • (4) Remote Repository에서 최신 것을 가져온다.
  • (5) Stash에 보관된 변경사항을 적용하여 머징한다.
  • (6) 변경된 사항을 Local Repository에 commit 한다.
  • $ git stash list  (1)
  • stash@{0}: WIP on master: …
  • stash@{1}: WIP on master: …
  • $ git stash show -p  (2)
  • $ git stash show –p stash@{1}    (3)
  • $ git stash apply  (4)
  • $ git stash clear  (5)
  • (1)Stash에 저장된 것을 조회한다. 현재 2개가 있다.
  • ...
  • ...
  • (2)최신의 것과 비교한다. –p 옵션을 주면 내용까지 확인 한다.
  • ...
  • (3) 이름 ‘stash@{1}’로 저장된 것과 비교한다.
  • ...
  • (4) 최신의 것으로 merging한다. ‘stash pop’을 사용할 경우 merging하고 삭제한다.
  • (5) Stash에 저장된 것을 전부 삭제한다.

.svn은 자기 변경본만 가지고 있지만 .git은 모든 서버정보 다 가짐

반응형

'git' 카테고리의 다른 글

git rebase, cherry-pick을 잘 이해해보자  (0) 2019.06.11
git tag  (0) 2019.06.07
git diff troubleshooting  (0) 2019.06.07
gerrit  (0) 2019.04.30
Git: ssh public key 등록  (0) 2019.04.26

+ Recent posts