내 연락처 정보
우편메소피아@프로톤메일.com
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
관련 주제:
git reuse recorded resolution
(rerere
) 충돌하는 Git 버전 병합Orphan branches
)만약에 git
라이브러리는 로컬에 있어 원격으로 코드를 공유할 필요가 없더라도 로컬 브랜치를 원격으로 공유해야 하는 창고처럼 관리할 수 있습니다. 이 예에서 볼 수 있듯이 먼저 창고를 로컬 영역에 복사해야 합니다. 이는 원격 라이브러리가 있음을 의미합니다.
# clone the jgit repository to match
$ git clone https://git.eclipse.org/r/jgit/jgit
$ cd jgit
# Whenever you start working on a bug fix or a new
# feature in your project, you should create a branch
$ git branch newBugFix
$ git branch
* master
newBugFix
# The newBugFix branch points to the current HEAD
# to verify this:
$ git log -1 newBugFix --format=format:%H
25fe20b2dbb20cac8aa43c5ad64494ef8ea64ffc
# edit branch description
$ git branch --edit-description newBugFix
# Add description in a newly opened editor
Refactoring the Hydro controller
The hydro controller code is currently horrible needs to be refactored.
# Show the description
$ git config --get branch.newBugFix.description
Refactoring the Hydro controller
The hydro controller code is currently horrible and needs to be refactored.
# Show the commit hash the new branch based on
$ cat .git/refs/heads/newBugFix
25fe20b2dbb20cac8aa43c5ad64494ef8ea64ffc
다음과 같은 것을 알 수 있다. ID
현재와 함께HEAD
~의ID
일관된.
참고: 새 분기를 생성한 후 다음을 사용하려면 이 분기로 전환해야 합니다.git checkout -b <newBranch>
펼치기: 팔로우하지 않는 경우 HEAD
새 브랜치를 생성하되 특정 커밋 ID(979e346
), 현재 이 버전을 기반으로 한 제출물은 다음과 같이 작성할 수 있습니다.
# new branch from commit ID
$ git branch anotherBugFix 979e346
$ git log -1 anotherBugFix --format=format:%h
979e346
$ git log -1 anotherBugFix --format=format:%H
979e3467112618cc787e161097986212eaaa4533
# checkout new branch
$ git checkout -b lastBugFix 979e346
지점 정보 보기:
git branch
: 지점명만git branch -v
: 1을 기준으로 주석을 달고 단순화했습니다. SHA-1
git branch -vv
: 2를 기준으로 원격 추적 지점 이름을 표시합니다.$ git branch -v
anotherBugFix 979e346 Interactive Rebase: Do actions if
* lastBugFix 979e346 Interactive Rebase: Do actions if
master 25fe20b Add missing package import for jg
newBugFix 25fe20b Add missing package import for jg
$ git branch -vv
anotherBugFix 979e346 Interactive Rebase: Do actions if e
* lastBugFix 979e346 Interactive Rebase: Do actions if e
master 25fe20b [origin/master] Add missing package
newBugFix 25fe20b Add missing package import for g
때로는 다른 사람의 코드 베이스를 복제하여 네이티브 코드가 생성될 수도 있습니다.이 시점에서 로컬 코드에는 일반적으로 호출되는 원격 창고가 있습니다.origin
원천.Git과 원격 코드 베이스를 이해하려면 다음으로 시작해 보세요.git status
명령은 다음과 같이 시작됩니다.
$ git checkout -b remoteBugFix --track origin/stable-3.2
Switched to a new branch 'remoteBugFix'
Branch 'remoteBugFix' set up to track remote branch 'stable-3.2' from 'origin'.
보이는,remoteBugFix
지점의 원격 추적 지점은 다음과 같습니다.origin/stable-3.2
.이때git status
결과는 현지HEAD
리모콘으로HEAD
로컬 지점을 원격 지점으로 빠르게 전달할 수 있는지 여부입니다. 예는 다음과 같습니다:
# Find a commit on remote branch
$ git log -10 origin/stable-3.2 --oneline
# Checkout specific SHA-1
$ git reset --hard 2e0d178
HEAD is now at 2e0d17885 Add recursive variant of Config.getNames() methods
# Use 'git status' to see the free benefit of Git
$ git status
On branch remoteBugFix
Your branch is behind 'origin/stable-3.2' by 9 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
알아채다:
fast-forward
, Git이 병합할 수 있음을 의미합니다. HEAD
최신 버전으로 이동하세요.git pull
이 명령은 실제로 다음 두 명령의 조합입니다.git fetch
git merge
(원격 추적 지점을 로컬 지점에 병합)위의 내용을 실행 git status
명령은 로컬 실행을 시뮬레이션하는 데 사용됩니다.git fetch
그 후 원격 지점의 새 콘텐츠가 로컬 추적 지점으로 당겨졌습니다.origin/stable-3.2
상태. 병합을 계속하면 실제로 로컬 분기와 동기화됩니다.
$ git merge origin/stable-3.2
Updating 2e0d17885..f839d383e
Fast-forward
.../org/eclipse/jgit/api/RebaseCommandTest.java | 213 +++++++++++++++++----
.../src/org/eclipse/jgit/api/RebaseCommand.java | 31 +--
.../jgit/errors/IllegalTodoFileModification.java | 59 ++++++
.../eclipse/jgit/lib/BaseRepositoryBuilder.java | 2 +-
.../src/org/eclipse/jgit/lib/Config.java | 2 +
.../src/org/eclipse/jgit/lib/RebaseTodoLine.java | 16 +-
6 files changed, 266 insertions(+), 57 deletions(-)
create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java
실행 결과에 따르면 다음과 같이 알 수 있다. git status
프롬프트에 명시된 대로 이 병합은 빨리 감기 병합(fast-forward merge
)
로컬 브랜치를 생성할 때 사용하는 것 외에도 --track
원격 추적 분기를 지정하고,git
기존 지점에 원격 지점을 지정하는 기능도 지원됩니다. 미리 로컬 브랜치를 생성하고 원격 브랜치를 연결하는 것을 잊어버린 경우,git
이 런타임 바인딩 기능은 유용합니다.
# Checkout a new branch without relating to its remote tracking branch
$ git checkout -b remoteBugFix2 2e0d17
Switched to a new branch 'remoteBugFix2'
# Set the tracking branch manually by using -u or --set-upstream-to
$ git branch --set-upstream-to origin/stable-3.2
Branch remoteBugFix2 set up to track remote branch stable-3.2 from origin.
# Validate current status
$ git status
On branch remoteBugFix2
Your branch is behind 'origin/stable-3.2' by 9 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working directory clean
# Same as the previous demo as expected.
# Update the branch (also a fast-forward merge with origin/stable-3.2)
$ git pull
Updating 2e0d17885..f839d383e
Fast-forward
.../org/eclipse/jgit/api/RebaseCommandTest.java | 213 +++++++++++++++++----
.../src/org/eclipse/jgit/api/RebaseCommand.java | 31 +--
.../jgit/errors/IllegalTodoFileModification.java | 59 ++++++
.../eclipse/jgit/lib/BaseRepositoryBuilder.java | 2 +-
.../src/org/eclipse/jgit/lib/Config.java | 2 +
.../src/org/eclipse/jgit/lib/RebaseTodoLine.java | 16 +-
6 files changed, 266 insertions(+), 57 deletions(-)
create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java
# The output is still the same as previous one as expected.
# Validate the current HEAD with origin/stable-3.2
$ git log -1 origin/stable-3.2 --format=format:%h
f839d383e
# Still the same.
이 책을 읽기 전에는 소프트웨어 제공 체인 및 분기 모델의 많은 예를 보셨을 것입니다. 또한 도구가 특정 워크플로우를 지원하면 이를 완전히 구현하기가 어렵다는 것을 알게 될 수도 있습니다. 원하는 애플리케이션 시나리오. Git은 거의 모든 워크플로 시나리오를 지원합니다. 일반적인 요구 사항은 기능을 병합할 때 병합 커밋을 생성할 수 있어야 한다는 것입니다(새 기능이 빨리 감기 모드에 통합될 수 있는 경우에도 마찬가지). 이러한 요구 사항은 특정 기능이 병합되었음을 나타내는 데 자주 사용되며 이 병합 작업이 명시적으로 웨어하우스에 저장되기를 원합니다.
팁
반면
Git
모든 제출 정보에 편리하고 빠르게 액세스할 수 있는 방법을 제공합니다.Git
라이브러리는 실제로 다음과 같이 사용되어야 합니다.통나무, 소스 코드뿐만 아니라 지원。
다음 예에서는 강제 병합 커밋을 생성합니다.
# Checkout branch stable-3.1 as remoteOldBugFix for use
$ git checkout -b remoteOldBugFix --track origin/stable-3.1
# force a merge commit
$ git merge origin/stable-3.2 --no-ff --edit --quiet
참고하시고 이용하세요 --edit
매개변수를 설정한 후 열리는 편집기에서 기본 병합 커밋 주석 정보를 수정할 수 있습니다.예에서--no-ff
빨리 감기 모드가 비활성화되었음을 나타냅니다.--quiet
화면 출력 내용을 단순화하는 데 사용됩니다. 최종 효과는 그림에 표시됩니다.
일반적인 방법과 비교를 위해 병합시 삭제 --no-ff
매개변수 항목:
# Reset to initial status
$ git reset --hard remotes/origin/stable-3.1
# Merge with fast forward by default
$ git merge origin/stable-3.2 --quiet
효과는 다음과 같습니다.
완전한 병합을 수행하는 것 외에도 Git을 사용하면 사용자가 병합된 콘텐츠에 개입하여 병합에 포함될 콘텐츠를 독립적으로 결정할 수 있습니다.사용--no-commit
매개변수,git
병합 커밋 전에 프로세스를 중단하여 사용자가 최종 커밋 전에 파일을 수정하거나 추가할 수 있도록 합니다. 예를 들어 프로젝트 버전 번호는 프로젝트의 기능 분기에서 수정되지만 기본 분기는 수정되지 않습니다. 기본 병합 작업은 버전 번호를 기능 분기의 버전 번호로 업데이트하지만 실제로 버전 번호를 변경하고 싶지는 않습니다.이 시간을 활용하세요--no-commit
피할 수 있습니다.
다음 예에서는 사용자 개입이 포함된 병합 작업을 보여줍니다. 병합할 때 라이선스 파일을 업데이트한 커밋을 수동으로 제외하려고 합니다.
# Clone repo into demo
$ git clone https://github.com/PacktPublishing/Git-Version-Control-Cookbook-Second-Edition_hello_world_flow_model.git demo
$ cd demo
# Checkout remote branch
$ git checkout -b remotePartlyMerge --track origin/release/1.0
Branch remotePartlyMerge set up to track remote branch release/1.0 from origin.
Switched to a new branch 'remotePartlyMerge'
# Force a merge commit with --no-commit flag
$ git merge origin/master --no-ff --no-commit
Automatic merge went well; stopped before committing as requested
# Exclude LICENSE file
$ git reset LICENSE
# Resume merging
$ git commit -m "Merging without LICENSE"
[remotePartlyMerge 1202b0e] Merging without LICENSE
# Check status (only LICENSE file remain untracked)
$ git status
On branch remotePartlyMerge
Your branch is ahead of 'origin/release/1.0' by 6 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
LICENSE
nothing added to commit but untracked files present (use "git add" to track)
# check difference excluding LICENSE file (only on Linux)
$ git diff origin/master !(LICENSE)
네트워크 속도 문제를 고려하여 샘플 저장소는 다음과 같습니다. Git-Version-Control-Cookbook-Second-Edition_hello_world_flow_model.git
이 학습 라이브러리에 추가(repos/ex3.3-no-commit-repo.rar
)