230607_git

김지태·2023년 6월 12일
0
post-thumbnail

branch
branch 조회
git branch : 로컬 브랜치에서 조회
git branch -r : 리모트 브랜치에서 조회
git branch -a : 로컬, 리모트 모두
branch 생성
git branch [브랜치 이름] : 로컬에서 브랜치 생성
branch 이동
git checkout [브랜치 이름]: 로컬에서 해당 브랜치로 이동
git checkout -b [브랜치 이름]: 로컬에서 해당 브랜치를 새롭게 만들어서 이동, 이미 있는 브랜치 이름 넣으면 안됨
git push origin [브랜치 이름] : 로컬에서 만든 브랜치를 리모트로 이동
branch 삭제
git branch -d [브랜치 이름] : 로컬에서 브랜치 삭제
git push origin --delete [브랜치 이름] : 리모트에 로컬에서 브랜치를 지웠다는 것을 알려줌
ex) git push origin --delete branch02 : "나 branch02를 지웠어." 라고 리모트 레포지토리에 알려줌.
(편집됨)

0111danye
5일 전
리모트 레포지토리에 있는 파일을 로컬로 복사하기
git clone https://[https://를 뺀 해당리포지토리 주소] (편집됨)

0111danye
5일 전
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws
$ git clone https://
Cloning into 'branch_project'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws
$ cd branch_project
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
$ ls -all
total 13
drwxr-xr-x 1 SAMSUNG 197609 0 Jun 7 11:50 ./
drwxr-xr-x 1 SAMSUNG 197609 0 Jun 7 11:50 ../
drwxr-xr-x 1 SAMSUNG 197609 0 Jun 7 11:50 .git/
-rw-r--r-- 1 SAMSUNG 197609 3238 Jun 7 11:50 .gitignore
-rw-r--r-- 1 SAMSUNG 197609 16 Jun 7 11:50 README.md
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
$ ls
README.md
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
$ git branch branch02
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
$ git branch
branch02

  • master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git checkout branch02
    Switched to branch 'branch02'
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git checkout -b branch01
    Switched to a new branch 'branch01'
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git branch
  • branch01
    branch02
    master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git push origin branch01
    Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'branch01' on GitHub by visiting:
    remote: https://github.com/DennyKim111/branch_project/pull/new/branc
    remote:
    To https://github.com/DennyKim111/branch_project
  • [new branch] branch01 -> branch01
    gi
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git push origin branch02
    Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'branch02' on GitHub by visiting:
    remote: https://github.com/DennyKim111/branch_project/pull/new/branc
    remote:
    To https://github.com/DennyKim111/branch_project
  • [new branch] branch02 -> branch02
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git branch -a
  • branch01
    branch02
    master
    remotes/origin/HEAD -> origin/master
    remotes/origin/branch01
    remotes/origin/branch02
    remotes/origin/master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git branch -r
    origin/HEAD -> origin/master
    origin/branch01
    origin/branch02
    origin/master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git branch -d branch01
    error: Cannot delete branch 'branch01' checked out at 'C:/Users/SAMSUNG/D
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git checkout branch02
    Switched to branch 'branch02'
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git branch -d branch01
    Deleted branch branch01 (was d28f0e8).
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git branch
  • branch02
    master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (branch
    $ git checkout master
    Switched to branch 'master'
    Your branch is up to date with 'origin/master'.
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch 0-a
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch -a
    0-a
    branch02
  • master
    remotes/origin/HEAD -> origin/master
    remotes/origin/branch01
    remotes/origin/branch02
    remotes/origin/master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch -d 0-a
    Deleted branch 0-a (was d28f0e8).
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch -a
    branch02
  • master
    remotes/origin/HEAD -> origin/master
    remotes/origin/branch01
    remotes/origin/branch02
    remotes/origin/master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch -d branch02
    Deleted branch branch02 (was d28f0e8).
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch -a
  • master
    remotes/origin/HEAD -> origin/master
    remotes/origin/branch01
    remotes/origin/branch02
    remotes/origin/master
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git push origin --delete branch01
    To https://github.com/DennyKim111/branch_project
  • [deleted] branch01
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git push origin --delete branch02
    To https://github.com/DennyKim111/branch_project
  • [deleted] branch02
    SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/branch_project (master
    $ git branch -a
  • master
    remotes/origin/HEAD -> origin/master
    remotes/origin/master

0111danye
5일 전
cat [보고 싶은 파일 이름]
-> 자동으로 파일의 내용이 출력됨
cat > [새로 작성하고 싶은 파일 이름]
-> 작성하고 싶은 내용 입력 그 후 엔터 치고 ctrl + d 눌러서 저장
cat >> [내용 덧붙이고 싶은 파일 이름]
-> 덧붙이고 싶은 내용 입력 그 후 엔터 치고 ctrl + d 눌러서 저장

0111danye
5일 전
git config --global core.editor : 에디터가 뭔지 확인
git config --global core.editor "code --wait" : code --wait으로 에디터 변경
사실 code로만 해도 되긴 하는데, --wait 하는 이유는 vs 코드에서 코드 수정할 때 터미널에서 코드를 못 치게 하는 기능을 설정하기 위해서 그렇다. 그리고 vim으로 하면 터미널로 수정할 수 있게 하는데, 불편함
git config --global -e : 글로벌에 설정된 에디터 옵션을 수정하겠다. (편집됨)

0111danye
5일 전
브랜치 이름으로 파일 내용 비교하기
git diff [확인하고 싶은 브랜치이름1][확인하고 싶은 브랜치 이름2] : vim 처럼 결과가 나옴
git difftool [확인하고 싶은 브랜치이름1][확인하고 싶은 브랜치 이름2] : 툴로 설정한 것(나는 vs code)으로 차이가 나타남
(편집됨)

0111danye
5일 전
36e0393e850d19aef34be6b82b68ac80002bb858
b705b3241e3f51299cb3c370c8f56045a2be789e

0111danye
5일 전
커밋 이름으로 파일 내용 비교하기
git difftool [커밋번호1][커밋번호2]

0111danye
5일 전
마지막 커밋과 그 전 커밋 비교하기
git difftool HEAD HEAD^
헤드는 지금, 헤드^ 는 그 전

0111danye
5일 전
마지막 커밋, 현재 수정 사항 비교 확인법
git difftool HEAD

0111danye
5일 전
로컬과 리모트 브랜치를 비교 확인
git difftool [로컬 브랜치 이름] origin/[리모트 브랜치 이름]

0111danye
5일 전
d88c200116fe518e413fe47206542f78efed9334
da2cfef40eb181c8742038a2386798af3667648d

0111danye
5일 전
문제 1 ~ 8번까지
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~
$ cd Documents/git_ws/
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws
$ git clone https://github.com/DennyKim111/diff_project.git
Cloning into 'diff_project'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws
$ cd diff_project/
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ ls
README.md
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ ls -all
total 9
drwxr-xr-x 1 SAMSUNG 197609 0 Jun 7 16:02 ./
drwxr-xr-x 1 SAMSUNG 197609 0 Jun 7 16:02 ../
drwxr-xr-x 1 SAMSUNG 197609 0 Jun 7 16:02 .git/
-rw-r--r-- 1 SAMSUNG 197609 14 Jun 7 16:02 README.md
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ cat > text.txt
my name is jitae (1, master)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ cat text.txt
my name is jitae (1, master)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)
text.txt
nothing added to commit but untracked files present (use "git add" to track)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git add text.txt
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged ..." to unstage)
new file: text.txt
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git commit -m 'create test.txt' text.txt
[master d88c200] create test.txt
1 file changed, 1 insertion(+)
create mode 100644 text.txt
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git push origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 320 bytes | 320.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/DennyKim111/diff_project.git
6c61290..d88c200 master -> master
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ cat > text.txt
my name is danye (2, master)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ cat text.txt
my name is danye (2, master)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git difftool HEAD
Viewing (1/1): 'text.txt'
Launch 'vscode' [Y/n]? y
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: text.txt
no changes added to commit (use "git add" and/or "git commit -a")
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git commit -m 'modify name -danye' text.txt
[master b669d20] modify name -danye
1 file changed, 1 insertion(+), 1 deletion(-)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git difftool master origin/master
Viewing (1/1): 'text.txt'
Launch 'vscode' [Y/n]? y
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (master)
$ git checkout -b dev
Switched to a new branch 'dev'
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ cat > text.txt
my name is j grotes kafka (3, dev)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git status
On branch dev
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: text.txt
no changes added to commit (use "git add" and/or "git commit -a")
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git add text.txt
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git status
On branch dev
Changes to be committed:
(use "git restore --staged ..." to unstage)
modified: text.txt
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git commit -m "modify name -j grotes kafka" text.txt
[dev da2cfef] modify name -j grotes kafka
1 file changed, 1 insertion(+), 1 deletion(-)
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git status
On branch dev
nothing to commit, working tree clean
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git difftool master dev
Viewing (1/1): 'text.txt'
Launch 'vscode' [Y/n]? y
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git log
commit da2cfef40eb181c8742038a2386798af3667648d (HEAD -> dev)
Author: DennyKim111 0111danye@gmail.com
Date: Wed Jun 7 16:19:09 2023 +0900
modify name -j grotes kafka
commit b669d203c4103227152bc073f47f4b88c0247648 (master)
Author: DennyKim111 0111danye@gmail.com
Date: Wed Jun 7 16:14:22 2023 +0900
modify name -danye
commit d88c200116fe518e413fe47206542f78efed9334 (origin/master, origin/HEAD)
Author: DennyKim111 0111danye@gmail.com
Date: Wed Jun 7 16:05:14 2023 +0900
create test.txt
commit 6c6129087ab0d858e1aff4d18a6c047057a0c970
Author: KIM JITAE 122429796+DennyKim111@users.noreply.github.com
Date: Wed Jun 7 16:00:35 2023 +0900
Initial commit
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ git difftool d88c200116fe518e413fe47206542f78efed9334 da2cfef40eb181c8742038a2386798af3667648d
Viewing (1/1): 'text.txt'
Launch 'vscode' [Y/n]? y
SAMSUNG@DESKTOP-U4636R1 MINGW64 ~/Documents/git_ws/diff_project (dev)
$ code .
image.png

image.png

0111danye
5일 전
Merge
git merge [머지 하고 싶은 브랜치 이름]

profile
데이터 분석가

0개의 댓글