programing

분기를 헤드로 빠르게 전달하는 방법

minimums 2023. 5. 8. 21:59
반응형

분기를 헤드로 빠르게 전달하는 방법

저는 오랜 기간 지사에서 개발한 후 마스터로 전환했습니다.로그에 다음이 표시됩니다.

당신의 지점은 167개의 커밋으로 '출발지/마스터'보다 뒤쳐져 있으며, 빠르게 전달될 수 있습니다.

노력했습니다.

git checkout HEAD

효과가 없습니다.마스터에 대한 중간 커밋을 확인했기 때문입니다.

어떻게 하면 마스터가 주도권을 잡을 수 있을까요?

해라git merge origin/master만약 당신이 그것이 단지 빨리 감기만 한다는 것을 확실히 하고 싶다면, 당신은 말할 수 있습니다.git merge --ff-only origin/master.

실행 중:

git checkout master
git pull origin

를 가져와서 병합합니다.origin/master지점(그냥 말할 수도 있음)git pullorigin이 기본값이므로).

당신의 상황에서는git rebase또한 속임수를 쓸 것입니다.마스터에 없는 변경사항이 없으므로 git는 빨리 감기만 합니다.기본 재배치 워크플로우로 작업하는 경우 실수해도 병합 커밋이 발생하지 않으므로 이 방법이 더 권장될 수 있습니다.

username@workstation:~/work$ git status
# On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
#   (use "git pull" to update your local branch)
#
nothing to commit, working directory clean
username@workstation:~/work$ git rebase
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/origin/master.
# On branch master
nothing to commit, working directory clean
git checkout master
git pull

그 일을 해야 합니다.

마스터와 다른 브랜치에서 작업할 때마다 "브랜치가 뒤에 있습니다"라는 메시지가 나타납니다. 누군가 마스터를 변경하면 "브랜치가 뒤에 있습니다."라는 메시지가 나타납니다.

(branch) $ //hack hack hack, while someone push the changes to origin/master
(branch) $ git pull   

이제 오리진/마스터 참조가 풀링되지만 마스터가 해당 참조와 병합되지 않습니다.

(branch) $ git checkout master
(master) $ 

이제 마스터가 오리진/마스터 뒤에 있으므로 빠르게 전달할 수 있습니다.

this will pull and merge (so merge also newer commits to origin/master)
(master) $ git pull 

this will just merge what you have already pulled
(master) $ git merge origin/master

이제 마스터와 오리진/마스터가 일치합니다.

빨리 회송하려는 사용자는 해당 분기를 체크아웃하지 않으면 다른 원격 분기(자체 포함)에 연결되지 않습니다.할 수 있는 일:

git fetch origin master:other

이는 기본적으로 다음의 인덱스를 빠르게 전달합니다.other로.origin/master만약 당신이 없다면other분점.이러한 방식으로 여러 분기를 빠르게 전달할 수 있습니다.

다른 분기에서 작업하는 동안 오래된 분기를 원격에서 해당 헤드로 업데이트하려는 경우:

git fetch origin master:master other:other etc:etc

만약 당신이 다른 지점에 서 있고 최신 버전의 마스터를 확인하고 싶다면 당신은 또한 할 수도 있습니다.

git checkout -B master origin/master

이 경우 빠르게 전달하려면 다음을 실행합니다.

$ git merge --ff-only origin/master

이는 다음을 사용합니다.--ff-only의 선택권.git merge질문이 "빨리 감기"를 구체적으로 묻기 때문입니다.

다음은 에서 발췌한 것입니다.git-merge(1)더 빠른 전환 옵션을 보여줍니다.

--ff, --no-ff, --ff-only
    Specifies how a merge is handled when the merged-in history is already a descendant of the current history.  --ff is the default unless merging an annotated
    (and possibly signed) tag that is not stored in its natural place in the refs/tags/ hierarchy, in which case --no-ff is assumed.

    With --ff, when possible resolve the merge as a fast-forward (only update the branch pointer to match the merged branch; do not create a merge commit). When
    not possible (when the merged-in history is not a descendant of the current history), create a merge commit.

    With --no-ff, create a merge commit in all cases, even when the merge could instead be resolved as a fast-forward.

    With --ff-only, resolve the merge as a fast-forward when possible. When not possible, refuse to merge and exit with a non-zero status.

자주 빠르게 전달하기 때문에 별칭이 필요합니다.

$ git config --global alias.ff 'merge --ff-only @{upstream}'

이제 이를 실행하여 빠르게 전달할 수 있습니다.

$ git ff

복잡성이 필요하지 않습니다.가지에 서서 당기기만 하면 됩니다.그것은 나에게 효과가 있었다.

아니면, 두 번째 시도로 git pull origin 마스터.하지만 첫 번째 명령에 운이 없는 경우에만 가능합니다.

뒤처져 당이나뭇어뒤있에경우는딘가지가신,경▁in우있▁where,는▁behind▁on▁cases'▁you▁branch▁a▁somewhere.
다음과 같은 로컬 변경사항은 기본값을 변경하는 것이 더 안전합니다.

git pull --rebase

이렇게 하면 불필요한 병합 커밋을 방지할 수 있습니다.

은 하는 것과 .)git fetch && git rebase.)

최신 원격 상태 위에서 로컬 변경사항을 이동하는 현재 로컬 추적기 분기의 기본을 변경하려면:

git fetch && git rebase

일반적으로 로컬 변경사항을 빨리 전달하고 삭제하려면(하드 재설정)*:

git fetch && git checkout ${the_branch_name} && git reset --hard origin/${the_branch_name}

로컬 변경사항을 빠르게 전달하고 유지하려면(기본값):

git fetch && git checkout ${the_branch_name} && git rebase origin/${the_branch_name}

- 의도하지 않은 하드 재설정으로 인해 발생한 변경 사항을 취소하려면 먼저 다음을 수행합니다.git reflog그러면 HEAD의 상태가 역순으로 표시됩니다.재설정 작업(일반적으로 명백함) 전에 HEAD가 가리키던 해시를 찾아 분기를 해당 해시로 하드 재설정합니다.

내 방식으로는, 그것은 모든 변경된 것을 머리로 되돌리고 가장 빠른 방법입니다.

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df

분기 포인터를 HEAD로 이동합니다.

git branch -f master

의 지점 용자사master이미 존재하기 때문에 Git에서는 사용자가 ...을 사용하지 않는 한 덮어쓸 수 없습니다. -f는 (이주은다나니다냅타음을장다이니▁(▁stands▁for)의 약자입니다.--force)

또는 rebase를 사용할 수 있습니다.

git rebase HEAD master

당신의 책임으로 하세요 ;)

언급URL : https://stackoverflow.com/questions/9512549/how-to-fast-forward-a-branch-to-head

반응형