티스토리 뷰

728x90
SMALL

브랜치 언제 사용하나요?

새로운 기능 추가

버그 수정

병합과 리베이스 테스트

이전 코드 개선

특정 커밋으로 돌아가고 싶을 때

 

[] 옵션, <> 필수

브랜치 생성

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline
e738af6 (HEAD -> master, origin/master) 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git branch
* master

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git branch mybranch1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git branch
* master
  mybranch1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --all
e738af6 (HEAD -> master, origin/master, mybranch1) 두 번째 커밋
25f256c 첫번째 커밋

 

브랜치 변경은 checkout 브랜치이름으로!! 체크섬으로하지마

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git checkout mybranch1
Switched to branch 'mybranch1'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git branch
  master
* mybranch1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git log --oneline --all
e738af6 (HEAD -> mybranch1, origin/master, master) 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ cat file1.txt
hello git
second

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ echo "third - my branch" >> file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ cat file1.txt
hello git
second
third - my branch

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git status
On branch mybranch1
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   file1.txt

no changes added to commit (use "git add" and/or "git commit -a")

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git add file1.txt
warning: LF will be replaced by CRLF in file1.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git commit
[mybranch1 7c25c74] mybranch1의 첫 번째 커밋
 1 file changed, 1 insertion(+)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git log --oneline --all
7c25c74 (HEAD -> mybranch1) mybranch1의 첫 번째 커밋
e738af6 (origin/master, master) 두 번째 커밋
25f256c 첫번째 커밋

빨리감기병합

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ echo "fourth - my branch" >> file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ cat file1.txt
hello git
second
third - my branch
fourth - my branch

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git status
On branch mybranch1
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   file1.txt

no changes added to commit (use "git add" and/or "git commit -a")

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git add file1.txt
warning: LF will be replaced by CRLF in file1.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git commit
[mybranch1 06d26b7] mybranch1 ??踰덉㎏ 而ㅻ컠
 1 file changed, 1 insertion(+)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ ggit log --oneline --all --graph
bash: ggit: command not found

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git log --oneline --all --graph
* 06d26b7 (HEAD -> mybranch1) mybranch1 두 번째 커밋
* 7c25c74 mybranch1의 첫 번째 커밋
* e738af6 (origin/master, master) 두 번째 커밋
* 25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ cat file1.txt
hello git
second

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git merge mybranch1
Updating e738af6..06d26b7
Fast-forward
 file1.txt | 2 ++
 1 file changed, 2 insertions(+)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --all --graph
* 06d26b7 (HEAD -> master, mybranch1) mybranch1 두 번째 커밋
* 7c25c74 mybranch1의 첫 번째 커밋
* e738af6 (origin/master) 두 번째 커밋
* 25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ cat file1.txt
hello git
second
third - my branch
fourth - my branch

 

* reset --hard는 아래 세 명령을 한번에 수행하는 명령

git checkout HEAD~2

git branch -f master

git checkout master

 

* HEAD~, HEAD^

HEAD~<숫자> : ~은 헤드의 부모커밋, HEAD~2는 헤드의 할아버지 커밋, HEAD~n은 n번째 위쪽 조상

HEAD^<숫자> : ^은 똑같이 부모커밋, HEAD^2는 두번째 부모. 병합 커밋처럼 부모가 둘 이상인 커밋에서 사용

 

빨리 감기 병합 상황에서 rebase해보기

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git checkout mybranch1
Switched to branch 'mybranch1'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git rebase master
Current branch mybranch1 is up to date.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git log --oneline --all
06d26b7 (HEAD -> mybranch1) mybranch1 두 번째 커밋
7c25c74 mybranch1의 첫 번째 커밋
e738af6 (origin/master, master) 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (mybranch1)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git rebase mybranch1
Successfully rebased and updated refs/heads/master.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --all
06d26b7 (HEAD -> master, mybranch1) mybranch1 두 번째 커밋
7c25c74 mybranch1의 첫 번째 커밋
e738af6 (origin/master) 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git push
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 599 bytes | 299.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/yoonminsang/hello-git-cli.git
   e738af6..06d26b7  master -> master

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git branch -d mybranch1
Deleted branch mybranch1 (was 06d26b7).

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --all -n2
06d26b7 (HEAD -> master, origin/master) mybranch1 두 번째 커밋
7c25c74 mybranch1의 첫 번째 커밋

 

배포 버전에 태깅하기

git tag -a -m <간단한 메시지> <태그 이름> [브랜치 또는 체크섬] : -a로 주석있는 태그를 생성합니다. 메시지와 태그 이름은 필수이며 브랜치 이름을 생략하면 HEAD에 태그를 생성합니다.

git push <원격저장소 별명> <태그 이름> : 원격 저장소에 태그를 업로드합니다.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline
06d26b7 (HEAD -> master, origin/master) mybranch1 두 번째 커밋
7c25c74 mybranch1의 첫 번째 커밋
e738af6 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git tag -a -m "첫 번째 태그 생성" v0.1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline
06d26b7 (HEAD -> master, tag: v0.1, origin/master) mybranch1 두 번째 커밋
7c25c74 mybranch1의 첫 번째 커밋
e738af6 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git push origin v0.1
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 187 bytes | 187.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/yoonminsang/hello-git-cli.git
 * [new tag]         v0.1 -> v0.1

 

cli로 3-way 병합하기(merge)

버그 수정 단계

1. (옵션) 오류가 없는 버전(주로 Tag가 있는 커밋)으로 롤백

2. [master] 브랜치로부터 [hotfix] 브랜치 생성

3. 빠르게 소스 코드 수정 / 테스트 완료

4. [master] 브랜치로 병합 (Fast-forward) 및 배포

5. 개발 중인 브랜치에도 병합(충돌 발생 가능성이 높음)

 

새로운 브랜치 및 커밋 생성

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git checkout -b feature1
Switched to a new branch 'feature1'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ echo "기능 1 추가" >> file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git add file1.txt
warning: LF will be replaced by CRLF in file1.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git commit
[feature1 eb39997] ?덈”??湲곕뒫 1 異붽?
 1 file changed, 1 insertion(+)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git log --oneline --graph --all -n2
* eb39997 (HEAD -> feature1) 새롱누 기능 1 추가
* 06d26b7 (tag: v0.1, origin/master, master) mybranch1 두 번째 커밋

 

 

hotfix 브랜치 생성, 커밋, master에 병합

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git checkout -b hotfix master
Switched to a new branch 'hotfix'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (hotfix)
$ git log --oneline --all -n2
43c0c7f (feature1) 새로운 기능 1 추가
06d26b7 (HEAD -> hotfix, tag: v0.1, origin/master, master) mybranch1 두 번째 커
밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (hotfix)
$ echo "some hot fix" >> file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (hotfix)
$ git add file1.txt
warning: LF will be replaced by CRLF in file1.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (hotfix)
$ git commit
[hotfix 4da3f23] hotfix ?ㅼ뒿
 1 file changed, 1 insertion(+)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (hotfix)
$ git log --oneline -n1
4da3f23 (HEAD -> hotfix) hotfix 실습

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (hotfix)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git merge hotfix
Updating 06d26b7..4da3f23
Fast-forward
 file1.txt | 1 +
 1 file changed, 1 insertion(+)

아직 추가작업 남아있다. hotfix는 버그 수정. feature1 브랜치에도 반영해야 한다. feautre1과 master 브랜치는 다ㅡㄹㄴ 분기로 진행되고 있기 때문에 3-way 병합.(빨리감기 안돼)

병합 및 충돌 해결하기1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git checkout feature1
Switched to branch 'feature1'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git log --oneline --all
4da3f23 (master, hotfix) hotfix 실습
43c0c7f (HEAD -> feature1) 새로운 기능 1 추가
06d26b7 (tag: v0.1, origin/master) mybranch1 두 번째 커밋
7c25c74 mybranch1의 첫 번째 커밋
e738af6 두 번째 커밋
25f256c 첫번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git merge master
Auto-merging file1.txt
CONFLICT (content): Merge conflict in file1.txt
Automatic merge failed; fix conflicts and then commit the result.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|MERGING)
$ git status
On branch feature1
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   file1.txt

no changes added to commit (use "git add" and/or "git commit -a")

 

vscode에서 수정(두 변경 사항 모두 수락)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|MERGING)
$ cat file1.txt
hello git
second
third - my branch
fourth - my branch
기능 1 추가
some hot fix

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|MERGING)
$ git add file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|MERGING)
$ git status
On branch feature1
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:
        modified:   file1.txt


User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|MERGING)
$ git commit
[feature1 c9c1466] Merge branch 'master' into feature1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git log --oneline --all --graph -n4
*   c9c1466 (HEAD -> feature1) Merge branch 'master' into feature1
|\
| * 4da3f23 (master, hotfix) hotfix 실습
* | 43c0c7f 새로운 기능 1 추가
|/
* 06d26b7 (tag: v0.1, origin/master) mybranch1 두 번째 커밋

리베이스(rebase)

reset --hard 및 rebase 시도

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git checkout feature1
Already on 'feature1'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git reseat --hard HEAD~
git: 'reseat' is not a git command. See 'git --help'.

The most similar command is
        reset

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git reset --hard HEAD~
HEAD is now at 43c0c7f 새로운 기능 1 추가

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git log --oneline --graph --all -n3
* 4da3f23 (master, hotfix) hotfix 실습
| * 43c0c7f (HEAD -> feature1) 새로운 기능 1 추가
|/
* 06d26b7 (tag: v0.1, origin/master) mybranch1 두 번째 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git rebase master
error: could not apply 43c0c7f... 새로운 기능 1 추가
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 43c0c7f... 새로운 기능 1 추가
Auto-merging file1.txt
CONFLICT (content): Merge conflict in file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|REBASE 1/1)
$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

git rebase master를 하고 vscode에서 코드수정.

 

충돌 해결 및 rebase 이어서 하기

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|REBASE 1/1)
$ git status
interactive rebase in progress; onto 4da3f23
Last command done (1 command done):
   pick 43c0c7f 새로운 기능 1 추가
No commands remaining.
You are currently rebasing branch 'feature1' on '4da3f23'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both modified:   file1.txt

no changes added to commit (use "git add" and/or "git commit -a")

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|REBASE 1/1)
$ git add file1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|REBASE 1/1)
$ git status
interactive rebase in progress; onto 4da3f23
Last command done (1 command done):
   pick 43c0c7f 새로운 기능 1 추가
No commands remaining.
You are currently rebasing branch 'feature1' on '4da3f23'.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   file1.txt


User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1|REBASE 1/1)
$ git rebase --continue
[detached HEAD 2e96ab7] 새로운 기능 1 추가
 1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/feature1.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git log --oneline --graph --all -n2
* 2e96ab7 (HEAD -> feature1) 새로운 기능 1 추가
* 4da3f23 (master, hotfix) hotfix 실습

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (feature1)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git merge feature
merge: feature - not something we can merge

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git merge feature1
Updating 4da3f23..2e96ab7
Fast-forward
 file1.txt | 1 +
 1 file changed, 1 insertion(+)

 

  3-way 병합 rebase
특징 머지 커밋 생성 현재 커밋들을 수정하면서 대상 브랜치 위로 재배치함
장점 한 번만 충돌 발생 깔끔한 히스토리
단점 트리가 약간 지저분해짐 여러 번 충돌이 발생할 수 있음

 

master브랜치만 사용해도 가지가 뻗어나온 경우가 생긴다. 이건 보통 두대의 pc에서 한 브랜치에 작업을 하는 경우에 생긴다. 한 pc에서 커밋을 생성하고 push를 했는데 다른 pc에서는 pull을 하지 않고 커밋을 하게 되면 이전 커밋을 부모로 한 커밋이 생긴다. 그 상황에서 뒤늦게 pull을 하면 자동으로 3-way 병합이 되기 때문에 그렇다. 즉 불필요하게 병합 커밋이 생긴 모양

=> reset ---hard로 병합 커밋을 되돌리고 rebase를 사용하자

 

보통 커밋 만들기

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ echo "master1" > master1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git add master1.txt
warning: LF will be replaced by CRLF in master1.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git commit -m "master 커밋 1"
[master c571a2d] master 커밋 1
 1 file changed, 1 insertion(+)
 create mode 100644 master1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git push origin master
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 12 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 845 bytes | 169.00 KiB/s, done.
Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/yoonminsang/hello-git-cli.git
   06d26b7..c571a2d  master -> master

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline -n1
c571a2d (HEAD -> master, origin/master) master 커밋 1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ ls
file1.txt  master1.txt

가지 커밋 만들기

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git reset --hard HEAD~
HEAD is now at 2e96ab7 새로운 기능 1 추가

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ echo "master2" > master2.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git add .
warning: LF will be replaced by CRLF in master2.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git commit -m "master2 커밋"
[master a39229c] master2 커밋
 1 file changed, 1 insertion(+)
 create mode 100644 master2.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --graph --all -n3
* a39229c (HEAD -> master) master2 커밋
| * c571a2d (origin/master) master 커밋 1
|/
* 2e96ab7 (feature1) 새로운 기능 1 추가

지금 git reset --hard HEAD~를 한건 다른 컴퓨터에서 풀을 안하고 커밋한것처럼 만든거야.

여기서 git full=git fetch+git merge이기 때문에 가지를 병합하기 위해서 병합 커밋이 생기고 지저분해져

 

git pull 수행결과

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git pull
Merge made by the 'recursive' strategy.
 master1.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 master1.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --graph --all -n4
*   5475ed1 (HEAD -> master) Merge branch 'master' of https://github.com/yoonminsang/hello-git-cli
|\
| * c571a2d (origin/master) master 커밋 1
* | a39229c master2 커밋
|/
* 2e96ab7 (feature1) 새로운 기능 1 추가

 

rebase로 가지 없애기

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git reset --hard HEAD~
HEAD is now at a39229c master2 커밋

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git rebase origin/master
Successfully rebased and updated refs/heads/master.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --all --graph -n3
* e484f34 (HEAD -> master) master2 커밋
* c571a2d (origin/master) master 커밋 1
* 2e96ab7 (feature1) 새로운 기능 1 추가

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 325 bytes | 108.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/yoonminsang/hello-git-cli.git
   c571a2d..e484f34  master -> master

 

충돌 해결, merge, rebase 무섭잖아. 그래서 임시 브랜치를 만들고 삭제하는거야

임시 브랜치 생성 사용 및 삭제

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git branch test feature1

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git checkout test
Switched to branch 'test'

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (test)
$ echo "아무말 대잔치" > test.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (test)
$ git add .
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (test)
$ git commit -m "임시 커밋"
[test 2ff83b2] 임시 커밋
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (test)
$ git log --oneline --graph --all -n4
* 2ff83b2 (HEAD -> test) 임시 커밋
| * e484f34 (origin/master, master) master2 커밋
| * c571a2d master 커밋 1
|/
* 2e96ab7 (feature1) 새로운 기능 1 추가

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (test)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git branch -D test
Deleted branch test (was 2ff83b2).

User@DESKTOP-VOH9EIA MINGW64 ~/Documents/hello-git-cli (master)
$ git log --oneline --graph --all -n3
* e484f34 (HEAD -> master, origin/master) master2 커밋
* c571a2d master 커밋 1
* 2e96ab7 (feature1) 새로운 기능 1 추가
728x90
LIST
댓글
공지사항