문제

나는 지점이있다 master 원격 브랜치를 추적합니다 origin/master.

이름을 바꾸고 싶습니다 master-old 로컬 및 리모컨 모두. 그게 가능합니까? 추적 한 다른 사용자를 위해 origin/master (그리고 항상 현지인을 업데이트했습니다 master 지점을 통해 git pull), 원격 지점으로 이름을 바꾸면 어떻게 될까요? 그들의 git pull 여전히 작동하거나 찾을 수없는 오류가 발생합니다. origin/master 더 이상?

그런 다음 더 나아가서 새로운 것을 만들고 싶습니다. master 분기 (로컬 및 원격). 다시 한 번, 내가이 일을 한 후에, 다른 사용자가하는 경우 지금 무슨 일이 일어날 지 git pull?

나는이 모든 것이 많은 문제를 일으킬 것이라고 생각한다. 내가 원하는 것을 얻는 깨끗한 방법이 있습니까? 아니면 그냥 떠나야할까요? master 그대로 새 지점을 만듭니다 master-new 그리고 그냥 거기에서 더 일하러?

도움이 되었습니까?

해결책

이름 바꾸기 가장 가까운 것은 리모컨에서 삭제 한 다음 다시 생성하는 것입니다. 예를 들어:

git branch -m master master-old
git push remote :master         # delete master
git push remote master-old      # create master-old on remote

git checkout -b master some-ref # create a new local master
git push remote master          # create master on remote

그러나 이것은 많은 경고가 있습니다. 먼저, 기존 체크 아웃은 이름 바꾸기에 대해 알지 못합니다 - Git Does ~ 아니다 지점 이름을 추적하려고 시도합니다. 새로운 경우 master 아직 존재하지 않으면 Git Pull이 오류가 발생합니다. 새로운 경우 master 생성 된. 풀은 병합을 시도합니다 master 그리고 master-old. 따라서 이전에 저장소를 체크 아웃 한 모든 사람의 협력이 없으면 일반적으로 나쁜 생각입니다.

참고 : 최신 버전의 GIT를 사용하면 기본적으로 마스터 브랜치를 원격으로 삭제할 수 없습니다. 설정하여 이것을 무시할 수 있습니다 receive.denyDeleteCurrent 구성 값 warn 또는 ignore원격 저장소. 그렇지 않으면 즉시 새 마스터를 만들 준비가되면 git push remote :master 발걸음을 내딛고 통과하십시오 --force ~로 git push remote master 단계. 리모컨 구성을 변경할 수 없으면 마스터 브랜치를 완전히 삭제할 수 없습니다!

이 경고는 현재 지점에만 적용됩니다 (보통 master 나뭇가지); 다른 지점은 위와 같이 삭제 및 재현 할 수 있습니다.

다른 팁

현재 켜져 있다고 가정합니다 master:

git push origin master:master-old        # 1
git branch master-old origin/master-old  # 2
git reset --hard $new_master_commit      # 3
git push -f origin                       # 4
  1. 먼저 a master-oldorigin 리포지토리, 기준 master 로컬 저장소에 커밋하십시오.
  2. 이 새로운 것을위한 새 지역 지점을 만듭니다 origin/master-old 분기 (추적 분기로 자동으로 설정).
  3. 이제 현지인을 가리 키십시오 master 당신이 그것을 가리키기를 원하는 어느 쪽이든.
  4. 마지막으로, 힘을 바꾸십시오 master 에서 origin 새로운 로컬을 반영하는 저장소 master.

(다른 방법으로 수행하면 master-old 추적하기 위해 올바르게 설정됩니다 origin/master-old. 이 글을 쓰는 시점에 게시 된 다른 솔루션은 포함되지 않습니다.)

git v1.7을 사용하면 이것이 약간 바뀌 었다고 생각합니다. 새로운 리모컨에 대한 로컬 브랜치의 추적 참조를 업데이트하는 것은 이제 매우 쉽습니다.

git branch -m old_branch new_branch         # Rename branch locally    
git push origin :old_branch                 # Delete the old branch    
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote
git checkout -b new-branch-name
git push remote-name new-branch-name :old-branch-name

수동으로 전환해야 할 수도 있습니다 new-branch-name 삭제하기 전에 old-branch-name

지점의 이름을 바꾸는 방법에는 여러 가지가 있지만 더 큰 문제에 중점을 둘 것입니다. "고객이 빠르게 진행되도록하고 현지에서 지점을 엉망으로 만들 필요가 없습니다.".

먼저 빠른 사진 :renaming master branch and allowing clients to fast-forward

이것은 실제로하기 쉬운 일입니다. 그러나 그것을 남용하지 마십시오. 전체 아이디어는 병합 커밋에 달려 있습니다. 그들은 빠르게 진행되고 다른 분기와의 역사를 다른 사람과 연결합니다.

지점의 이름 바꾸기 :

# rename the branch "master" to "master-old"
# this works even if you are on branch "master"
git branch -m master master-old

새로운 "마스터"지점 만들기 :

# create master from new starting point
git branch master <new-master-start-point>

병합 제작 부모-자식 역사를 갖기로 커밋 :

# now we've got to fix the new branch...
git checkout master

# ... by doing a merge commit that obsoletes
# "master-old" hence the "ours" strategy.
git merge -s ours master-old

그리고 Voila.

git push origin master

이것은 생성하기 때문에 작동합니다 merge 커밋 허용 빠르게 진행됩니다 새로운 개정의 지점.

현명한 병합 커밋 메시지 사용 :

renamed branch "master" to "master-old" and use commit ba2f9cc as new "master"
-- this is done by doing a merge commit with "ours" strategy which obsoletes
   the branch.

these are the steps I did:

git branch -m master master-old
git branch master ba2f9cc
git checkout master
git merge -s ours master-old

나는 당신이 여전히 당신의 것과 같은 상황에 대해 묻고 있다고 가정합니다. 이전 질문. 즉, Master-New는 역사에 Mas 그것은 중요하지 않습니다 어떻게 당신은 주인이 이전의 주인의 후손이 아닌 주에 들어가고, 단순히 그 상태에 있다는 것입니다.

Mas 마치 리포지토리에서 마스터 이전 및 마스터 새를 병합 한 것처럼 마치. 당신이 여기서하려는 일을 감안할 때, 합병은 충돌을 일으킬 것입니다. (그들이 해결되었고 결과가 저장소로 다시 밀려 나면, 당신은 훨씬 더 나쁜 상태에있을 것입니다 - 두 버전의 역사가 거기에있을 것입니다.)

단순히 질문에 답하기 위해 : 때로는 역사에 실수가있을 것임을 받아 들여야합니다. 이것은 괜찮습니다. 모든 사람에게 발생합니다. git.git 리포지토리에는 리버 된 커밋이 있습니다. 중요한 것은 일단 우리가 역사를 출판하면 모든 사람이 신뢰할 수있는 것입니다.

*그렇다면, 이것은 일부 변경 사항을 마스터로 밀고 예전에 새 지점을 만드는 것과 같습니다. 문제 없어요.

그만큼 선택된 답변 내가 시도했을 때 실패했습니다. 오류가 발생합니다. refusing to delete the current branch: refs/heads/master. 나에게 효과가있는 것을 게시 할 것 같아요 :

git checkout master             # if not in master already

git branch placeholder          # create placeholder branch
git checkout placeholder        # checkout to placeholder
git push remote placeholder     # push placeholder to remote repository

git branch -d master            # remove master in local repository
git push remote :master         # remove master from remote repository.

트릭은 원격 저장소로 밀기 직전에 자리 표시 자에게 체크 아웃하는 것입니다. 나머지는 자기 설명이며 마스터 브랜치를 삭제하고 원격 저장소로 푸시하는 것이 지금 작동합니다. 발췌 여기.

좋은. 내 2 센트. 서버에서 로그인하고 GIT 디렉토리로 가서 베어 리포지토리에서 지점을 바꾸는 것은 어떻습니까? 동일한 지점을 다시 업로드하는 것과 관련된 모든 문제가 없습니다. 실제로 '클라이언트'는 수정 된 이름을 자동으로 인식하고 원격 참조를 변경합니다. 나중에 (또는 이전) 지점의 로컬 이름을 수정할 수도 있습니다.

는 어때:

git checkout old-branch-name
git push remote-name new-branch-name
git push remote-name :old-branch-name
git branch -m new-branch-name

이것은 내가 아는 가장 단순하고 가장 '읽을 수있는'방법입니다.

-M을 사용하여 '이동'로컬 브랜치

git branch -m my_old_branch_name my_new_branch_name

'이동'브랜치를 리모콘으로 밀고 -U를 사용하여 '업스트림'을 설정하십시오.

git push origin -u my_new_branch_name

( '업스트림'을 설정하는 것은 본질적으로 로컬 브랜치를 리모컨에 연결하여 가져 오기, 풀 및 푸시와 같은 것들이 작동합니다)

리모컨에서 이전 브랜치를 삭제하십시오

git push origin -D <old_name>

(첫 번째 단계에서 '이동'했기 때문에 현지 지점이 이미 사라졌습니다)

다음을 수행 할 수 있습니다.

git -m master master-old #rename current master
git checkout -b master   #create a new branch master
git push -f origin master #force push to master

그러나 다른 사람들 이이 저장소를 공유하는 경우 힘 추진은 나쁜 생각입니다. 포스 푸시는 그들의 개정 내역이 새로운 것과 상충 될 것이다.

확인, 둘 다를 바꾸는 것 장소 상에서 그리고 on 원격 매우 쉽습니다! ...

지점에 있다면 쉽게 할 수 있습니다.

git branch -m <branch>

또는 그렇지 않은 경우 :해야합니다.

git branch -m <your_old_branch> <your_new_branch>

그런 다음 삭제를 다음과 같이 리모콘으로 푸시하십시오.

git push origin <your_old_branch>

이제 푸시하려고하는 동안 상류 오류가 발생하면 간단히 수행하십시오.

git push --set-upstream origin <your_new_branch>

또한 실제 명령 줄의 단계를 표시하기 위해 아래 이미지를 만들고 단계를 따르면 좋습니다.

enter image description here

다음은 작업을 수행하기 위해 쉘 스크립트에 저장할 수 있습니다.

예를 들어:

remote="origin"

if [ "$#" -eq 0 ] # if there are no arguments, just quit
then
    echo "Usage: $0 oldName newName or $0 newName" >&2
    exit 1
elif
    [ "$#" -eq 1 ] # if only one argument is given, rename current branch
then 
    oldBranchName="$(git branch | grep \* | cut -d ' ' -f2)" #save current branch name
    newBranchName=$1
else
    oldBranchName=$1
    newBranchName=$2
fi

git branch -m $oldBranchName $newBranchName

git push $remote :$oldBranchName #delete old branch on remote
git push --set-upstream $remote $newBranchName # add new branch name on remote and track it

여기에서 기본 원격 이름 "원점"은 하드 코딩되어 있으므로 구성 가능한 경우 스크립트를 확장 할 수 있습니다!

그런 다음이 스크립트는 BASH 별칭, GIT 별칭 또는 Sourcetree 사용자 정의 작업과 함께 사용할 수 있습니다.

나는 열쇠가 당신이 더블 이름 바꾸기 : master 에게 master-old 그리고 또한 master-new 에게 master.

다른 모든 답변에서 나는 이것을 합성했다.

doublerename master-new master master-old

우리가 먼저 정의 해야하는 곳 doublerename 배쉬 기능 :

# doublerename NEW CURRENT OLD
#   - arguments are branch names
#   - see COMMIT_MESSAGE below
#   - the result is pushed to origin, with upstream tracking info updated
doublerename() {
  local NEW=$1
  local CUR=$2
  local OLD=$3
  local COMMIT_MESSAGE="Double rename: $NEW -> $CUR -> $OLD.

This commit replaces the contents of '$CUR' with the contents of '$NEW'.
The old contents of '$CUR' now lives in '$OLD'.
The name '$NEW' will be deleted.

This way the public history of '$CUR' is not rewritten and clients do not have
to perform a Rebase Recovery.
"

  git branch --move $CUR $OLD
  git branch --move $NEW $CUR

  git checkout $CUR
  git merge -s ours $OLD -m $COMMIT_MESSAGE

  git push --set-upstream --atomic origin $OLD $CUR :$NEW
}

이것은 역사 변화와 유사합니다 git rebase 분기 내용물은 상당히 다르지만 고객이 여전히 안전하게 빠르게 git pull master.

git update-ref newref oldref
git update-ref -d oldref newref
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top