code

체크 아웃하지 않고 분기 포인터를 다른 커밋으로 이동

codestyles 2020. 9. 30. 10:46
반응형

체크 아웃하지 않고 분기 포인터를 다른 커밋으로 이동


체크 아웃 된 분기의 분기 포인터를 이동하려면 git reset --hard명령을 사용할 수 있습니다 . 그러나 체크 아웃되지 않은 분기의 분기 포인터를 다른 커밋을 가리 키도록 이동하는 방법 (추적 된 원격 분기와 같은 다른 모든 항목을 유지)?


NB 단순히 분기 를 다른 커밋 으로 이동하려는 경우 가장 쉬운 방법은

git branch -f branch-name new-tip-commit

Chris Johnsen의 답변 .

임의의 심판에 대해 할 수 있습니다. 분기 포인터를 이동하는 방법은 다음과 같습니다.

git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

일반적인 형식 :

git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

원하는 경우 리플 로그 메시지에 대한 nits를 선택할 수 있습니다. branch -f하나가 하나와 다르다고 생각 reset --hard하며 이것은 정확히 둘 중 하나가 아닙니다.


git branch -f <branch-name> <new-tip-commit>

git reset --hard커밋 참조를 전달할 수도 있습니다 .

예를 들면 :

git checkout branch-name
git reset --hard new-tip-commit

나는 이와 같은 일을 거의 자주하지 않는다는 것을 알게되었습니다.

이 역사를 가정

$ git log --decorate --oneline --graph
* 3daed46 (HEAD, master) New thing I shouldn't have committed to master
* a0d9687 This is the commit that I actually want to be master

# Backup my latest commit to a wip branch
$ git branch wip_doing_stuff

# Ditch that commit on this branch
$ git reset --hard HEAD^

# Now my changes are in a new branch
$ git log --decorate --oneline --graph
* 3daed46 (wip_doing_stuff) New thing I shouldn't have committed to master
* a0d9687 (HEAD, master) This is the commit that I actually want to be master

토론을 풍부하게하기 위해 myBranch분기를 현재 커밋 으로 이동 하려면 다음 두 번째 인수를 생략하십시오.-f

예:

git branch -f myBranch


나는 일반적으로 rebaseDetached HEAD 상태에 있을 때 이것을합니다. :)


에서 gitk --all:

  • 원하는 커밋을 마우스 오른쪽 버튼으로 클릭하십시오.
  • -> 새 브랜치 생성
  • 기존 지점의 이름을 입력
  • 해당 이름의 이전 분기를 대체것인지 확인 하는 대화 상자에서 Enter 키를 누릅니다 .

기존 분기를 수정하는 대신 다시 생성 하면 추적 분기 정보가 손실됩니다 . (이것은 일반적으로 리모트가 하나 뿐이고 로컬 브랜치가 리모트의 해당 브랜치와 이름이 같은 간단한 사용 사례에서는 문제가되지 않습니다. 자세한 내용은 주석을 참조하십시오.이 단점을 지적 해 주신 @mbdevpl에게 감사드립니다.)

gitk대화 상자에 덮어 쓰기, 기존 수정 또는 취소의 3 가지 옵션이있는 기능이 있으면 멋질 것 입니다.


Even if you're normally a command-line junkie like myself, git gui and gitk are quite nicely designed for the subset of git usage they allow. I highly recommend using them for what they're good at (i.e. selectively staging hunks into/out of the index in git gui, and also just committing. (ctrl-s to add a signed-off: line, ctrl-enter to commit.)

gitk is great for keeping track of a few branches while you sort out your changes into a nice patch series to submit upstream, or anything else where you need to keep track of what you're in the middle of with multiple branches.

I don't even have a graphical file browser open, but I love gitk/git gui.


The recommended solution git branch -f branch-pointer-to-move new-pointer in TortoiseGit:

  • "Git Show log"
  • Check "All Branches"
  • On the line you want the branch pointer to move to (new-pointer):
    • Right click, "Create Branch at this version"
    • Beside "Branch", enter the name of the branch to move (branch-pointer-to-move)
    • Under "Base On", check that the new pointer is correct
    • Check "Force"
    • Ok

enter image description here

enter image description here


Honestly, I'm surprised how nobody thought about the git push command:

git push -f . <destination>:<branch>

The dot ( . ) refers the local repository, and you may need the -f option because the destination could be "behind its remote counterpart".

Although this command is used to save your changes in your server, the result is exactly the same as if moving the remote branch (<branch>) to the same commit as the local branch (<destination>)

참고URL : https://stackoverflow.com/questions/5471174/move-branch-pointer-to-different-commit-without-checkout

반응형