본문 바로가기

GIT10

[Git] Tip: Get Diff and Apply using File Commit을 만들진 않고, 임시 테스트 용 정도의 수정을 공유하고 싶을 때가 있습니다. 그럴 때 유용하게 사용할 수 있는 방법입니다. Extract Changes to a File 다음 명령으로 간단하게 현재 수정 중인 사항을 파일로 추출합니다. $ git diff > diff.patch 이제 diff.patch에 변경 내용이 담겨 있고, 이것을 공유하면 됩니다. Apply Changes from a File 이제, 공유받은 파일에서 변경 내용을 가져와 적용해 볼게요. $ git apply diff.patch Working branch를 확인해보면 변경 내용이 잘 적용된 것을 확인하실 수 있습니다. Wrap Up 이번에는 임시 수정 사항을 파일로 추출하고 이를 적용하는 방법에 대해 살펴 보았습니다. .. 2023. 6. 8.
[Git] Tip: Change Past Commit Messages 가끔 커밋 메세지가 잘못 작성된 것을 나중에 발견하게 되는 경우가 있습니다. 이것을 수정하는 방법에 대해 공유드리겠습니다. How to change 설명을 위해 임의의 repository를 작성하였습니다. 각자 자신의 환경을 생각하시면 될 것 같아요. 먼저, commit의 hash를 얻기 위하여 log를 보겠습니다. $ git log --oneline 이미 3번째 commit까지 올렸는데, 첫 번째 commit 메세지에 오타를 발견했네요. 이제, 현재 commit에서 해당 커밋까지 interactive하게 rebase를 합니다. $ git rebase -i 1243b39^ 다음과 같이 interactive한 설정을 할 수 있는 창이 나타납니다. 스샷과 같이 변경을 원하는 commit에 edit comma.. 2023. 4. 27.
[Git] Tip: Using BeyondCompare4 as Diff Tool Prerequisite BC4(BeyondCompare 4)가 설치되어 있고, 환경변수에 등록이 되어 command line에서 사용이 가능해야합니다. Setting BC4를 git의 diff tool로 사용하기 위하여 등록을 해줍니다. $ git config --global diff.tool bc4 Usage 단순히 diff를 하게되면 파일 단위로 하기 때문에 사용에 불편함이 있습니다. 따라서, 전체 폴더 단위로 하도록 사용하는 편을 추천드립니다. $ git difftool --dir-diff 2022. 2. 23.
[Git] Tip: Cherry-pick from a Different Repository 간혹 같은 code base를 갖지만 분화되어 나눠진 별도의 repository로 운영되는 프로젝트들이 있습니다. 이 때, 서로 다른 repository에서 특정 commit을 cherry-pick 하고 싶은 경우가 있습니다. 공통적으로 적용될 수 있는 수정이나 신규 기능들을 갖고 올 경우죠. 이 때, 간단하게 다음을 통해 적용해볼 수 있습니다. Remote Repository 추가 $ git remote add Commit Fetching 처음 repository를 추가하면 자동으로 fetching을 하기 때문에, 건너뛰셔도 되는 부분이지만, 이미 추가된 repository거나 혹시 모를 상황에 대비해 remote repository의 변경 사항을 가져오는 것이 좋습니다. $ git fetch Cher.. 2021. 11. 30.
[Git] Tip: Revert Merged Commit 우리는 때로 되돌렸다는 기록을 남기면서 commit을 되돌려야할 때가 있습니다. 이럴 때, revert 명령을 사용하게 되죠. 하지만, 되돌릴 커밋이 merged commit일 때가 문제죠. 2개의 commit이 병합되어있을 경우, 되돌릴 때 어떤 commit으로 되돌려야할 지가 문제죠. 이제 이 문제를 하나씩 살펴봅시다. Merged | \ C B | / A 위와 같은 상태에서 merged commit을 revert해 봅시다. $ git revert 이런 식으로 명령을 내리면 git이 명령 수행을 할 수 없다고 불평을 합니다. 당연한 일이죠. 되돌렸을 때, C로도 갈 수 있고, B로도 갈 수 있기 때문입니다. 이럴 때, -m 옵션을 사용할 수 있습니다. 쉽게 말해 revert 후, 어느 쪽을 따라 갈까.. 2021. 3. 5.
[Git] Tip: Change committer and author from already committed commit If you use multiple accounts for git, you can make a mistake. I sometimes make a mistake as well. Let's fix this. I made a test repository with a test account. Now, do the magic! git filter-branch -f --env-filter ' OLD_EMAIL="old@test.com" NEW_NAME="NewName" NEW_EMAIL="new@test.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$NEW_NAME" export GIT_COMMITTER_EMAIL.. 2021. 2. 15.
[Git] Restore Command This command restores working tree files. This command is experimental. (v2.29.0) Description Restore specified paths in the working tree with some contents from a restore source. If a path is tracked but does not exist in the restore source, it will be removed to match the source. Usage Restore Specified Paths $ git restore Specify the Restore location If neither option is specified, by default.. 2020. 10. 23.
[Git] Switch Command This command helps to switch branches. This command is experimental. (v2.29.0) Description Switch to a specified branch. The working tree and the index are updated to match the branch. Usage Switch to Specified Branch $ git switch Create a New Branch and Switch to the Branch $ git switch -c $ git switch --create $ git switch -c Forced Switch to Specified Branch Proceed even if the index or the w.. 2020. 10. 23.
[Git] Config Command The config command is used to config the Git. Scope The configuration of Git has three scopes. system : /etc/gitconfig global : ~/.gitconfig local : /.git/config Usually, the configurations to be applied commonly to all projects are placed in global, and the configurations to be applied per project are placed in local. The priority is local > global > system. Usage $ git config --system $ git co.. 2020. 9. 23.
[Git] Getting Started git Git is a distributed version control system. It is designed to handle everything from small to very large projects with speed and efficiency. Installation - Mac Mac has Git already. $ brew install git git-lfs - Linux (Ubuntu) $ sudo apt install git git-lfs - Windows $ choco install -y git git-lfs Git Basics Repository The git repository is a repository managed by the Git. This is a simple us.. 2020. 9. 23.