'프로그램 사용/Version Control'에 해당되는 글 137건

  1. 2025.12.11 git revert
  2. 2025.12.09 .gitconfig insteadof
  3. 2025.05.22 git master -> main branch
  4. 2025.01.16 git local branch, merge master
  5. 2025.01.16 git switch
  6. 2024.09.19 git stash drop , clear
  7. 2024.06.19 git submodule ... 2?
  8. 2022.09.05 git diff --staged
  9. 2021.09.14 git reset 서버 commit
  10. 2021.06.21 git blame

reset은 아예 없애는거라 내 취향은 아니고

revert 가 딱이긴 한데 의미가 내가 생각하던 것과는 조금 달랐다

 

예를 들어

git log 에서

hash 1111

hash 2222

hash 3333

hash 4444

 

git revert 2222 라고 하면

hash 2222 에서 했던 녀석만을 되돌리게 된다.

 

정리 하자면

revert 는 "hash 의 해당 commit을 돌린다" 이기 때문에

돌아가고 싶은 커밋이 아니라

없애고 싶은 커밋을 명시해야 한다.

 

man page 에도 존재하는 커밋을 되돌린다고 되어있다.

git-revert - Revert an existing commit

Synopsis
git revert [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>

Description

Given one existing commit, revert the change the patch introduces, and record a new commit that records it. This requires your working tree to be clean (no modifications from the HEAD commit).

Note: git revert is used to record a new commit to reverse the effect of an earlier commit (often a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-reset(1), particularly the --hard option. If you want to extract specific files as they were in another commit, you should see git-checkout(1), specifically the git checkout <commit> - <filename> syntax. Take care with these alternatives as both will discard uncommitted changes in your working directory.

[링크 : https://linux.die.net/man/1/git-revert]

 

만약 돌려야 한다면 한번에 될진 모르겠지만 1111, 2222를 revert 해야 할지도? (확인필요)

 

$ git log --oneline
17b787d bug3 fixed
1fefb57 bug2 fixed
8b3560b bug1 fixed
784065c feature1 developed
...
이제 우리는 이러한 버그 수정을 없애고 저장소를 bug1 fixed 상태 이전의 상태로 되돌리기로 결정했습니다.

따라서 --no-commit 옵션과 함께 git revert 명령을 사용할 수 있습니다. 명령 구문은 git revert --no-commit <commit>입니다.

따라서 완료된 버그 수정의 세 커밋을 되돌리려면 다음과 같이 해야 합니다.

$ git revert --no-commit 17b787d784065c
$ git revert --no-commit 1fefb57
$ git revert --no-commit 8b3560b

[링크 : https://www.delftstack.com/ko/howto/git/git-revert-multiple-commits/]

[링크 : https://medium.com/@rnrjsah789/git-revert-4c569366a77b]

[링크 : https://www.inflearn.com/community/questions/172695/%EC%97%AC%EB%9F%AC%EA%B0%9C%EC%9D%98-%EC%BB%A4%EB%B0%8B%EC%9D%84-revert?srsltid=AfmBOoo4CTQkAtobmxI0lo6YlKOM1mC1_XZ7rhbI66F8q7CUayTbRIDG]

 

git revert를 하면 자동으로 커밋메시지를 생성해서 커밋하는데 

여러개 돌릴때 마다 메시지 남기면 번거로우니 쭈르르르륵 되돌려 버릴땐 -n 옵션 주면 된다고 한다.

-n, --no-commit
Usually the command automatically creates a commit with a commit log message stating which commit was reverted. This flag applies the change necessary to revert the named commit to your working tree and the index, but does not make the commit. In addition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning state of your index.
This is useful when reverting more than one commits' effect to your index in a row.

[링크 : https://linux.die.net/man/1/git-revert]

'프로그램 사용 > Version Control' 카테고리의 다른 글

.gitconfig insteadof  (0) 2025.12.09
git master -> main branch  (0) 2025.05.22
git local branch, merge master  (0) 2025.01.16
git switch  (0) 2025.01.16
git stash drop , clear  (0) 2024.09.19
Posted by 구차니

전역설정으로 등록하면 저장소 주소가 달라졌을때 간단하게(!) 연결을 변경해 줄 수 있다.

[링크 : https://gist.github.com/Kovrinic/ea5e7123ab5c97d451804ea222ecd78a]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git revert  (0) 2025.12.11
git master -> main branch  (0) 2025.05.22
git local branch, merge master  (0) 2025.01.16
git switch  (0) 2025.01.16
git stash drop , clear  (0) 2024.09.19
Posted by 구차니

아놔... 어떻게 보면 그 쪽에서는 중요할지도 모르지만

컴퓨터 쪽 까지도 PC가 침범하게 될 줄이야.. -_-

 

[링크 : https://fabric0de.tistory.com/5]

[링크 : https://castellan.tistory.com/79]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git revert  (0) 2025.12.11
.gitconfig insteadof  (0) 2025.12.09
git local branch, merge master  (0) 2025.01.16
git switch  (0) 2025.01.16
git stash drop , clear  (0) 2024.09.19
Posted by 구차니

브랜치를 잘 쓸줄 몰랐는데 이번에 쓸일이 생겨서 찾아보는 중

목표는

master 브랜치에는 릴리즈 수준으로만 커밋하고

실제 개발은 로컬 브랜치에서 작업하고

결과물만 master로 merge 하는 것 이다.

 

명령어는 아래와 같이 master와 dev를 오가면서 해야 하는데

혹시나 해서 dev 에서 작업중 master에서 추가되는데 별 문제가 없었다.

굳이(?) 필요했다면 dev에서 master를 merge 하면 되긴 할 듯.

 

master dev
git init
git touch README
git add README
git commit -m "initial upload for project"
 
git branch dev
git checkout dev (혹은 git switch dev)
'dev' 브랜치로 전환합니다
 
  touch Makefile
mkdir app
cd app
touch Makefile
touch main.c
cd ..
git add Makefile app/
git commit -m "application added"

git switch master
'master' 브랜치로 전환합니다
touch RELEASE
git add RELEASE
git commit -m "add release rule"
git checkout dev (혹은 git switch dev)
'dev' 브랜치로 전환합니다
 
  cd app
vi Makefile
vi main.c
git add Makefile
git commit -m "makefile fixed"
git add mainc.
git commit -m "skeleton added"
git switch master
'master' 브랜치로 전환합니다
cd ..
git checkout dev -- . (현 위치에 dev 를 체크아웃함)
git add Makefile app/
git commit -m "feature added for dev branch"
 

 

$ git help checkout
       git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]
           This is similar to the previous mode, but lets you use the
           interactive interface to show the "diff" output and choose which
           hunks to use in the result. See below for the description of
           --patch option.

 

[링크 : https://inpa.tistory.com/entry/GIT-⚡%EF%B8%8F-깃-Branch-정리-branch-checkout-merge-rebase]

'프로그램 사용 > Version Control' 카테고리의 다른 글

.gitconfig insteadof  (0) 2025.12.09
git master -> main branch  (0) 2025.05.22
git switch  (0) 2025.01.16
git stash drop , clear  (0) 2024.09.19
git submodule ... 2?  (0) 2024.06.19
Posted by 구차니

git checkout branch_name 과 동등하다고 한다.

[링크 : https://inpa.tistory.com/entry/GIT-⚡%EF%B8%8F-깃-Branch-정리-branch-checkout-merge-rebase]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git master -> main branch  (0) 2025.05.22
git local branch, merge master  (0) 2025.01.16
git stash drop , clear  (0) 2024.09.19
git submodule ... 2?  (0) 2024.06.19
git diff --staged  (0) 2022.09.05
Posted by 구차니

오래 안쓰고 까먹는 stash 들이 있어서 지우는 방법 검색

git stash drop #  가장 최신 stash 삭제
git stash clear # 모든 stash 삭제

[링크 : https://wakestand.tistory.com/846]

[링크 : https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-Stashing%EA%B3%BC-Cleaning]

[링크 : https://iiii.tistory.com/156]

 

git stash clear 복구

[링크 : http:// https://systorage.tistory.com/entry/Git-git-stash-clear-복구하기]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git local branch, merge master  (0) 2025.01.16
git switch  (0) 2025.01.16
git submodule ... 2?  (0) 2024.06.19
git diff --staged  (0) 2022.09.05
git reset 서버 commit  (0) 2021.09.14
Posted by 구차니

테스트 필요

 

현재 경로에서 서브모듈로 다른 프로젝트 추가하기

$ git submodule add https://github.com/chaconinc/DbConnector

 

서브모듈 초기화하고 받아오기 (저장소만 업데이트)

$ git submodule init
Submodule 'DbConnector' (https://github.com/chaconinc/DbConnector) registered for path 'DbConnector'
$ git submodule update

 

혹은 받아올 때 서브모듈 초기화 같이 하기(이게 편리할 듯)

$ git clone --recurse-submodules https://github.com/chaconinc/MainProject

 

서브모듈의 저장소 갱신시 최신버전을 가져오기(git pull ?)

$ git submodule update --remote

 

make 할때 git submodlue update --remote를 추가해두니 편하긴 한데

이래저래 귀찮다. -ㅁ-

 

[링크 : https://git-scm.com/book/ko/v2/Git-도구-서브모듈]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git switch  (0) 2025.01.16
git stash drop , clear  (0) 2024.09.19
git diff --staged  (0) 2022.09.05
git reset 서버 commit  (0) 2021.09.14
git blame  (0) 2021.06.21
Posted by 구차니

stage 상태의 소스에 대해서 unstage 하지 않고 diff 하는 방법

 

[링크 : https://frhyme.github.io/git/git_diff_staged/]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git stash drop , clear  (0) 2024.09.19
git submodule ... 2?  (0) 2024.06.19
git reset 서버 commit  (0) 2021.09.14
git blame  (0) 2021.06.21
git pull rebase 설정  (0) 2021.06.02
Posted by 구차니

마지막 커밋 1개 날리고, 강제로 서버에 푸시

$ git reset --hard HEAD~1
$ git push -f

 

그래도 이력을 남기는 revert가 좋을 듯.

다만 돌릴게 많으면 돌렸다는 이력 자체도 잔뜩 생긴다고 하니

되돌릴일을 만들지 않는게 최선.. ㅠㅠ

$ git revert [hash]

 

[링크 : https://jupiny.com/2019/03/19/revert-commits-in-remote-repository/]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git submodule ... 2?  (0) 2024.06.19
git diff --staged  (0) 2022.09.05
git blame  (0) 2021.06.21
git pull rebase 설정  (0) 2021.06.02
git log --stat  (0) 2021.05.10
Posted by 구차니

svn 처럼 git 에도 소스라인 단위로 누가 커밋한 건지 추적하는 기능이 없나 봤는데 있다!

 

$ git blame
사용법: git blame [<옵션>] [<리비전-옵션>] [<리비전>] [--] <파일>

    <리비전-옵션>은 git-rev-list(1)에 설명되어 있습니다

    --incremental         블레임 항목을 찾자마자 점진적으로 표시합니다
    -b                    가장자리 커밋에 대해 빈 SHA-1을 표시합니다 (기본값: 꺼짐)
    --root                최상위 커밋을 가장자리 커밋으로 취급하지 않습니다 (기본값: 꺼짐)
    --show-stats          작업 비용 통계를 표시합니다
    --progress            강제로 진행 상황을 표시합니다
    --score-debug         블레임 항목에 대해 출력 점수를 표시합니다
    -f, --show-name       원래 파일 이름 표시 (기본값: 자동)
    -n, --show-number     원래 줄 번호 표시 (기본값: 하지 않음)
    -p, --porcelain       컴퓨터 처리용으로 설계된 형식으로 표시합니다
    --line-porcelain      줄마다 커밋 정보가 표시되는 사용자용 형식으로 표시합니다
    -c                    git-annotate와 동일한 형식을 사용합니다 (기본값: 꺼짐)
    -t                    내부 형식으로 시각을 표시합니다 (기본값: 꺼짐)
    -l                    길게 커밋 SHA1을 표시합니다 (기본값: 꺼짐)
    -s                    작성자 이름과 시각을 표시하지 않습니다 (기본값: 꺼짐)
    -e, --show-email      작성자 이름 대신에 전자메일을 표시합니다 (기본값: 꺼짐)
    -w                    공백 문자 차이점을 무시합니다
    --indent-heuristic    diff를 향상하는데 실험적인 휴리스틱을 사용합니다
    --minimal             더 일치하는 항목을 찾는데 더 시간을 소모합니다
    -S <파일>             git-rev-list를 호출하는 대신 <파일>에서 리비전을 사용합니다
    --contents <파일>     <파일>의 내용을 최종 이미지로 사용합니다
    -C[<점수>]            파일 내부와 파일 사이의 복사된 줄을 찾습니다
    -M[<점수>]            파일 내부와 파일 사이의 옮겨진 줄을 찾습니다
    -L <n,m>              n,m줄 (1번 줄부터 시작) 사이의 범위만 처리
    --abbrev[=<n>]        SHA-1 표시에 <n>개의 숫자를 사용합니다

[링크 : https://git-scm.com/docs/git-blame/2.31.0]

'프로그램 사용 > Version Control' 카테고리의 다른 글

git diff --staged  (0) 2022.09.05
git reset 서버 commit  (0) 2021.09.14
git pull rebase 설정  (0) 2021.06.02
git log --stat  (0) 2021.05.10
git stash  (0) 2021.05.09
Posted by 구차니