programing

Git에 따르면 누가 "우리"이고 누가 "그들"입니까?

instargram 2023. 7. 1. 08:02
반응형

Git에 따르면 누가 "우리"이고 누가 "그들"입니까?

Gitrebase 이후 및 기타 상황에서 당사가 삭제한 것으로 표시된 일부 파일을git status보고를 하다Git에 따르면 우리는 누구이고 왜?

제가 이 나뭇가지에 앉아 있는데 저를 위해 일하는 것을 말하는 건가요?아니면 제가 기반을 두고 있는 지점에서 일하는 사람들과 자신을 지칭하는 것입니까?

병합할 때us병합할 지점을 가리킵니다.them합병할 지점

베이스를 다시 칠 때,us브랜치를 하며, 상류분다참니조them당신이 이동하는 지점입니다.리베이스의 경우에는 약간 반직관적입니다.

그 이유는 Git가 리베이스를 위해 동일한 병합 엔진을 사용하기 때문입니다. 그리고 그것은 실제로 당신의 물건을 업스트림 브랜치로 집어넣고 있습니다. us안으로,them에서

Git에 따르면 "우리"/"우리"와 "그들"/"그들"은 누구입니까?

(이것은 또한 "기트베이스는 어떻게 작동하며 정확히 어떤 일이 일어나고 있는가?"라는 질문에 답합니다.)

모든 경우:

대략적인 일반인의 용어로 (감사합니다, @user20358):

"us"는 이미 레포에 있는 코드이고, "them"은 [당신이 병합하려는] 코드입니다.

보다 완전한 용어로:

  1. "우리"(또는 "우리") = 현재 체크아웃된 커밋(HEAD) 현재 git는 충돌을 일으키는 동작을 수행합니다(나중에 자세히 설명).
  2. "them"(또는 "commit") = 다른 커밋, 충돌을 유발하는 작업을 수행하는 순간 git에 의해 체크아웃되지 않습니다(나중에 자세히 설명).

문서:HEAD갈등을 유발하는 행동을 하는 순간에는 반드시 다음과 같은 것은 아닙니다.HEAD를 입력하는 git 명령어를 합니다.이것은 이해하는 데 필수적입니다.Git은 체크아웃을 좀 하고 변경할 수 있습니다.HEAD(커밋이 체크아웃됨) 충돌을 유발하는 작업을 실행하기 전에 "우리"와 "그들"이 훈련되지 않은 사람의 눈에 바뀌거나 뒤로 표시됩니다.

세부적으로 병합, 체리픽, 리베이스, 되돌리기의 4가지 경우:

  1. git merge (음악):
    1. 명령: " 샘명령플:
      git checkout master
      git merge feature_branch  # merge feature_branch into master
      
    2. "우리"/"우리" =HEAD,어느 것이master이 지점에 입니다.master당신이 도망친 시간에git merge feature_branch.
    3. "그들"/"그들" =feature_branch당신이 합병하려는 지점이 어디입니까?master.
  2. git cherry-pick (음악):
    1. 명령: " 샘명령플:
      git checkout feature_branch
      git cherry-pick some_commit  # apply some_commit to feature_branch
      
    2. "우리"/"우리" =HEAD,어느 것이feature_branch이 지점에 입니다.feature_branch당신이 도망친 시간에git cherry-pick some_commit.
    3. "그들"/"그들" =some_commit당신이 체리로 장식하고 있는 약속이 무엇입니까?feature_branch.
  3. git rebase반복적이지만,이 됩니다 ()▁(다있수:니▁makes습,▁totally▁but()
    1. 명령: " 샘명령플:
      git checkout feature_branch
      git rebase master  # rebase feature_branch onto latest master
      
    2. 위 및/또는 오른쪽에 최근 또는 최신 커밋이 있는 이 다이어그램(https://asciiflow.com 참조):
      #             Prior to rebase: feature_branch
      #             received new commits while
      #             master did too
      # 
      #                           master
      #                           x
      #                           |          feature_branch
      #                           x          y
      #                           |          |
      #                           x          y
      #                           |         /
      # git merge-base      ────► x--y--y--y
      # master feature_branch     |
      #                           x
      # 
      # 
      #             After rebase: feature_branch has
      #             been completely cherry-picked onto
      #             the end of master
      # 
      #                                   feature_branch
      #                                   y'
      #                                   |
      #                                   y'
      #                                  /
      #                         y'--y'--y'
      #                         |
      #                  master x
      #                         |
      #                         x
      #                         |
      #                         x
      #                         |
      #                         x
      #                         |
      #                         x
      
    3. "우리"/"우리" =HEAD이것은 업스트림 분기입니다. 처음에는 마지막으로 커밋한 다음,다음에는 새로운 커밋을 추가합니다. (이것은 까다롭습니다!).이것은 당신이 입력했을 때git rebase masterGit은 먼저 커밋을 체리로 분류하기 시작하는 출발점으로 체크아웃한 다음, 어떤 커밋에서 시작할지 결정합니다.feature_branch 당신의 체리픽(즉리픽체, 당것것어느중의신즉▁of-▁your▁to▁() 중 어느 것을 고르십시오.feature_branch 커이아설않았다니에 .master)을 것입니다merge-base 다 )feature_branch그리고.master은 그고그찾수있다습니을을것리와 함께 찾을 수 .git merge-base master feature_branch), 그리고 나서 이것이 끝나면 첫 번째 것부터 체리 따기 커밋을 시작합니다.merge-base에 한 번에 한 번씩,한 번에 한 한 번, 한 번, 한 번, 한 번, 한 번, 한 번, 한 에 한 번씩.feature_branch에의 master모든 따서새 "모운을" "기로" "본합" "니다" "라든" ""본" "기"" "asing니" "▁thereby다" "reb"" "합▁all▁"" "new▁""y feature_branch의 최신로으에.master새것처럼y'커밋따라서 "우리"/"우리" =HEAD하지만 깃이 이 기지를 수행하기 위해 비밀리에 새로운 점검을 했기 때문에HEAD입력할 때 있었던 분기가 아닙니다.git rebase master대신에, 우리, 또는HEAD 마입니다막입니다.x 약속합니다. 수다하착.master첫 번째 기간 동안 충돌이 발생하는 경우cherry-pickcommit, 아니면약무엇든간에이이속새로운▁or▁new에간▁whatever,▁it▁commit▁is.y'마지막으로 성공적으로 체리로 장식되었습니다.master나중에 체리픽을 따는 동안 충돌이 발생하면 됩니다.그러므로 그들은 약간의 다른 약속입니다.y에서 feature_branch 이운것적에있것는고에 입니다.HEAD체리픽을 통해, 처음부터 순서대로.y 약속합니다. 수다하착.feature_branch바로 다음에. git merge-base master feature_branchy 약속합니다. 수다하착.feature_branch바로 아래의 "그들"에 대한 설명도 참조하십시오.
    4. "그들"/"그들" = 일부y에서 feature_branch 체크아웃한 새로체한사적것다입니용에 입니다.HEAD서, 디에어HEAD 마입니다막입니다.x 약속합니다. 수다하착.master중 첫 된 체리픽 작업 중 입니다.y' 위에 있습니다.master~하듯이feature_branch는 "기반 변경" 또는 한 번에 하나의 커밋(새로운 커밋 문자열에 따라)을 변경합니다.git merge-base master feature_branch에 대한 feature_branch에서 에로 이동합니다.master바로 위의 "우리"에 대한 설명도 참조하십시오.
  4. git revert(직관적이지 않음):
    1. 명령: " 샘명령플:
      git checkout feature_branch
      # create a new commit to undo the changes from some_previous_commit
      # within feature_branch
      git revert some_previous_commit  
      
    2. 이에 대한 자세한 하위 수준의 역학은 여기에 있는 다른 답변 하단의 "결과 및 결론" 섹션과 여기에 있는 @torek의 매우 길고 자세한 답변을 참조하십시오.
    3. "우리"/"우리" =HEAD,어느 것이feature_branch이 지점에 입니다.feature_branch당신이 도망친 시간에git revert some_previous_commit보다 구체적으로, "우리"/"우리"는 다음과 같이 표현되는 변경 사항을 포함합니다.git diff some_previous_commit..HEAD을 되돌리는입니다(" (커밋이반시변사다의니항경입터점부환는되커다▁which▁from니▁at사▁are▁point입항▁the변▁being▁the▁changes경▁(▁commit).some_previous_commit는 지금 있는 는 우리가 지금 하고 있는 약속에 전념했습니다.
    4. "them"/"message" = (의 역 또는 역)some_previous_commit변경 사항을 되돌리는 커밋입니다(위에 새 커밋을 만들어 실행).feature_branch즉, "그들"/"그들"은 다음과 같이 표현되는 변화를 포함합니다.git diff some_previous_commit..some_previous_commit~서, 디에어some_previous_commit~상위 커밋입니다.some_previous_commit즉, "them"/"thirs"는 다음과 반대입니다.some_previous_commit변경 내용의 반대를 포함하므로 취소하기 위해some_previous_commit의 변경 사항.

예제 사용 사례:

병합 충돌 해결 예:

# 1. Merge `feature_branch` into `master`, accepting ALL of 
# `master`'s (`ours`) changes in the event of 
# any merge conflicts! 
git checkout master
git merge -X ours feature_branch

# 2. Merge `feature_branch` into `master`, accepting ALL of 
# `feature_branch`'s (`theirs`) changes in the event of 
# any merge conflicts! 
git checkout master
git merge -X theirs feature_branch

여기 몇 가지 더 있습니다.이것들은 바로 위의 두 가지 예가 아니라 제가 가장 많이 사용하는 기술들입니다.

# 3. Assuming this merge attempt results in merge conflicts in
# these 3 files, but we know all of the changes on the `master`
# branch side are the ones we wish to keep, check out these 3 
# files from `master` (`--ours`) to overwrite the conflicted
# files. Then, add these now-fixed files to stage them for 
# committing, and continue (finish) the merge. 
git checkout master
git merge feature_branch
git checkout --ours -- path/to/somefile1.c path/to/somefile2.c path/to/somefile3.c
git add path/to/somefile1.c path/to/somefile2.c path/to/somefile3.c
git status 
git merge --continue

# 4. Assuming this merge attempt results in merge conflicts in
# these 3 files, but we know all of the changes on the `feature_branch`
# side are the ones we wish to keep, check out these 3 
# files from `feature_branch` (`--theirs`) to overwrite the conflicted
# files. Then, add these now-fixed files to stage them for 
# committing, and continue (finish) the merge. 
git checkout master
git merge feature_branch
git checkout --theirs -- path/to/somefile1.c path/to/somefile2.c path/to/somefile3.c
git add path/to/somefile1.c path/to/somefile2.c path/to/somefile3.c
git status 
git merge --continue

매우 유용함: 전체 충돌 폴더가 존재하는 경우 에서 충돌하는 모든 변경 사항을 수락하도록 지정할 수도 있습니다.--ours또는--theirs전체 폴더에 대한 분기를 한 번에 지정합니다. 다음과 같이!:

**최상의 병합 충돌 해결 예:**

# 5. [BEST EXAMPLE] Assuming this merge attempt results in merge conflicts in
# a bunch of files, some of which are inside `path/to/some/dir`, I can
# choose to accept the changes from one side or the other **for 
# all conflicts within files inside this directory**, like this!:
git checkout master
git merge feature_branch

# Keep `--theirs` for all conflicts within files inside this dir
git checkout --theirs -- path/to/some/dir
# OR: keep `--ours` for all conflicts within files inside this dir
git checkout --ours -- path/to/some/dir

# Add (stage for committing) all changes within files inside this dir 
# all at once
git add path/to/some/dir 
git status 
git merge --continue 

리방법처path does not have our version또는path does not have their version 예:

다음과 같은 작업을 실행할 경우:

git checkout --ours -- path/to/some/dir

하지만 소용이 없었어요!아무 것도 안 했어요.대신 다음 오류를 출력합니다.

error: path 'path/to/some/dir/file1.cpp' does not have our version
error: path 'path/to/some/dir/file2.cpp' does not have our version
error: path 'path/to/some/dir/file3.cpp' does not have our version

문제는 이러한 오류가 발생한 파일이 에서 삭제된다는 것입니다.our측면, 그래서 우리는 반드시.git rm하기 에 각각 합니다.git checkout --ours -- path/to/some/dir.

git rm path/to/some/dir/file1.cpp path/to/some/dir/file2.cpp \
path/to/some/dir/file3.cpp

# then try again
git checkout --ours -- path/to/some/dir

대신 이 작업을 수행하여 프로세스를 자동화할 수도 있습니다.

git checkout --ours -- path/to/some/dir \
|& gawk '{ print $3 }' | xargs git rm

git checkout --ours -- path/to/some/dir

위의 명령에 대한 자세한 설명은 여기에서 내 대답을 참조하십시오. git checkout --file spec에 삭제된 파일이 포함된 경우 우리의 명령입니다.

경고 경고!

아래에 설명된 문제의 보다 자세한 예는 여기에서 제 다른 답변을 참조하십시오.

마세요git checkout -- path/to/some/dir,도 아니다git checkout some_branch -- path/to/some/dir갈등 해결 중에 (예를 들어)merge위의 예와 같이 충돌), 모든 파일을 체크아웃하려는 경우를 제외하고는HEAD 는또에에서.some_branch 각각에서, 리에토디렉.path/to/some/dir로컬 파일을 해당 파일로 덮어쓰므로 서로 충돌하는 변경 사항을 어느 한쪽에서만 수락할 수 없습니다.

즉, 충돌 해결 중에는 다음과 같은 작업이 수행됩니다.

양호:

# GOOD :)
# Accept all conflicts from one side or the other (while still 
# merging changes from both sides into one, in the event of being
# in the middle of a `git merge`).

git checkout --ours -- path/to/some/dir
# OR
git checkout --ours -- path/to/some/file

측면의 변경 사항만 수락합니다.--ours그것이 우리가 원하는 것이라면 언제나 좋고 안전한 것이지만, 반면에 이것입니다.

불량:

# BAD :(
# OVERWRITE all files with these files from `some_branch` instead,
# thereby _losing_ any changes and/or files contained in the other
# side but which are not in `some_branch`.

git checkout some_branch -- path/to/some/dir 
# OR
git checkout some_branch -- path/to/some/file

충돌하는 변경사항만 제외하고 지정된 대로 전체 디렉토리 또는 전체 파일을 완전히 체크아웃하고 덮어씁니다.이는 사용자가 실수로 전체 체크아웃을 통해 한쪽 또는 다른 쪽에서 변경사항을 삭제할 수 있음을 의미합니다.git checkout some_branch와의 갈등 해결보다는git checkout --ours또는git checkout --theirs이러한 이유로, 다음과 같이 충돌 해결 중일 때는 또는 사용하는 것이 좋습니다.git merge,git cherry-pick,git rebase또는git revert.

git checkout some_branch -- file_or_dir_paths당신은 이 동작을 이해하고 그것이 당신이 원하는 것이기 때문에, 당신도 이것을 알아야 합니다: 그렇게 전체 디렉토리를 체크아웃하는 것은 존재하지 않는 그 디렉토리의 로컬 파일을 삭제하지 않습니다.some_branch당신이 예상했던 것처럼.하지만 로컬에 하지 않는 경우 파일 .some_branch따라서 이러한 모든 파일을 수동으로 제거해야 합니다.그것을 명심하세요. 그렇지 않으면 결국 여러분을 매우 혼란스럽게 만들 것입니다.이에 대한 자세한 내용은 여기에 있는 다른 답변( 답변에도 좋은 해결책이 있음)과 여기에 있습니다.

추가/추가 참고 사항 및 팁:

  1. 중 할 경우 할 수 .git merge,git cherry-pick,git rebase,git revert 단, 단, 할, 명, 심, 외, 합, 제, 은, 니, 것, 다, 등, 는, 있, 요, 필, 가, 합, 외, 니, ▁except, ▁etc, 제theirs그리고.ours위에서 설명한 것처럼 각 충돌 해결 유형에 대한 평균입니다.
  2. 다과같은지이사수있용도습다니할름을점음과 같은 지점 .master또는feature_branch신에를 -X ours/-X theirs그리고.--ours그리고.--theirs경고: 지점 이름을 전달하는 것이 더 쉽고 명확해 보일 수 있지만, 이렇게 하면 파일 내의 충돌만 해결하는 것이 아니라 전체 파일 또는 디렉터리 교체를 수행하기 때문에 변경사항에 위험할 수 있습니다.위의 "경고 경고" 섹션을 참조하십시오.그러나 전체 파일을 교체하려면 서로 충돌하는 변경 사항을 수락하는 대신 다음과 같은 방법이 있습니다.
    # See "WARNING WARNING WARNING" section above.
    git checkout feature_branch -- path/to/somefile1.c path/to/somefile2.c path/to/somefile3.c
    
  3. 또한 파일을 개별적으로 지정하는 대신 전체 디렉토리를 체크아웃할 수 있습니다!여기에 있는 이 답변과 여기에 있는 나의 답변 그리고 여기에 있는 나의 다른 답변보세요.방금 테스트해 봤어요.이것도 됩니다.그러나 다시 한 번 위의 "경고 경고" 섹션에 주의하십시오.이렇게 하면 전체 폴더에 대해 한 쪽 또는 다른 쪽에서 충돌하는 변경사항을 수락하는 대신 전체 디렉토리를 교체할 수 있습니다.
    # Check out ALL files from feature_branch which are in
    # directory "path/to/dir". See "WARNING WARNING WARNING"
    # section above.
    git checkout feature_branch -- path/to/dir
    
  4. 으로 만약당의로사용면다한요으세적기하억도, 이신세요▁remember,▁you,ally▁intention를 사용한다면 기억하세요.git checkout feature_branch -- path/to/dir됨/예상됨path/to/dir에 것feature_branch,그렇지 않을 것이다.한 후에는 로컬 파일 시스템에서 해당 .checkout 내용하십시오.자세한 내용은 여기를 참조하십시오.
    1. 파일 또는 디렉토리 체크아웃에 대한 모든 정보
    2. --soft또는--hard경로별 git 재설정

참조:

  1. [항상 참조하는 내 대답!] "git에서 파일 또는 디렉터리 체크아웃에 대한 모든": 다른 지점에서 파일 하나만 가져오는 방법은 무엇입니까?
  2. [나의 대답]git는 경로별로 하드/소프트 리셋을 할 수 없습니까? --> 마지막에 있는 "배경 지식" 섹션에서 git 용어와 정의를 참조하십시오!
  3. ["그들가 ["과 "가 무엇을 의미하는지에 대한 나의 대답git revert기트 반전 속의 그들과 우리는 누구입니까?
  4. 은 항상 [@LeGEC "우우/리가"입니다.HEAD그리고 "그들/그들의"는 항상 다른 분기 또는 커밋입니다] "그들"과 "기트 반전"에서 "우리"는 누구입니까?
  5. [내가 이해한 것과 관련하여 교차 확인한 기존 답변.git merge그리고.git rebaseGit에 따르면 "우리"는 누구이고 "그들"은 누구입니까?
  6. man git checkout"gitrebasegit pull 중에 기본 설정과 해당 설정이 서로 바뀐 것으로 나타날있습니다."
    --ours, --theirs
        When checking out paths from the index, check out stage #2 (ours) or #3 (theirs) for
        unmerged paths.
    
        Note that during git rebase and git pull --rebase, ours and theirs may appear swapped;
        --ours gives the version from the branch the changes are rebased onto, while --theirs
        gives the version from the branch that holds your work that is being rebased.
    
        This is because rebase is used in a workflow that treats the history at the remote as
        the shared canonical one, and treats the work done on the branch you are rebasing as the
        third-party work to be integrated, and you are temporarily assuming the role of the
        keeper of the canonical history during the rebase. As the keeper of the canonical
        history, you need to view the history from the remote as ours (i.e. "our shared
        canonical history"), while what you did on your side branch as theirs (i.e. "one
        contributor’s work on top of it").
    
  7. [내 질문에 대한 대답]:파일을 개별적으로 지정할 필요 없이 전체 디렉터리에서 모든 파일을 체크아웃하기 위해 디렉터리 경로를 git로 전달할 수 있습니다.특정 디렉터리에 대해서만 "그들의" 분기에서 git merge 충돌을 수락하려면 어떻게 해야 합니까?
  8. [my answer] git checkout - 파일 사양에 삭제된 파일이 포함된 경우 우리의 것.
  9. 코드에 넣을 예쁜 ASCII 그림이나 다이어그램을 그리는 경우: https://asciiflow.com/ .

추가 연구:

  1. [이은 아직 스스로 공부해야 합니다!--완료; 2020년 1월 7일 현재 여기서 제 답을 파악하고 업데이트했습니다.] "깃 되돌리기"에서 "그들"과 "우리"는 누구입니까?
  2. [나는 여전히 이것을 공부하고 읽을 필요가 있다] get checkout -- 우리는 병합되지 않은 파일 목록에서 파일을 제거하지 않습니다.

참고 항목:

  1. 자주 참조하고 "기트 기초"로 간주되는 답변에 대한 빠른 링크:
    1. 다른 분기에서 분기 깃을 만드는 다양한 방법
    2. 파일 또는 디렉토리 체크아웃에 대한 모든 정보
    3. Git에 따르면 누가 "우리"이고 누가 "그들"입니까?

언급URL : https://stackoverflow.com/questions/21025314/who-is-us-and-who-is-them-according-to-git

반응형