简体   繁体   中英

How to point branch head in git to master?

I need to make commit, which is circled, linked to the head~1 of a master. In other words I want to remove all commits and branches, except one commit.
在此处输入图片说明

If I understand your question correctly:

  • You want to discard the batter-icons branch. That's easy:

     $ git branch -D batter-icons
  • You want to rebase ups-icons-support on master~1 . So, do that:

     $ git checkout ups-icons-support $ git rebase master~1

Now you have:

           * ups-icons-support
  master * |
          \|
           * master~1

If your goal it to replace the old master branch, you could:

$ git checkout master
$ git reset --hard ups-icons-support

You need to do two tasks:

  • Remove the other branch.

You need the uppercase "d" because these commits are going to lose all references to get them.

git branch -D batter-icons
  • Take only the last commit of ups-icons-support in master~1

This is done with git rebase --onto

git checkout ups-icons-support
git rebase --onto master~1 HEAD~1 ups-icons-support
  1. --onto master~1 is where you want to start the rebase.
  2. HEAD~1 is the first commit you want to rebase.
  3. ups-icons-support is the end of the rebase.

Thanks for answer, here is how I made it

git log --oneline --decorate --all --graph * dd9bda6 (origin/batter-icons, batter-icons) на всякий * 16b9233 battery to primary * cb61d3a icons 1 | * 3824a5e (origin/ups-icons-support, ups-icons-support) XFCE-powemanager-UPS-icons | * 4c8ecae Reverted index.theme to original(as was after forking) |/ * 7ca1226 (HEAD, origin/master, origin/HEAD, master) 96 support * 66c295a folders and index for panel folder * c4ca2a7 1.3.1 * dd9bda6 (origin/batter-icons, batter-icons) на всякий * 16b9233 battery to primary * cb61d3a icons 1 | * 3824a5e (origin/ups-icons-support, ups-icons-support) XFCE-powemanager-UPS-icons | * 4c8ecae Reverted index.theme to original(as was after forking) |/ * 7ca1226 (HEAD, origin/master, origin/HEAD, master) 96 support * 66c295a folders and index for panel folder * c4ca2a7 1.3.1

git branch -D batter-icons

git branch -D --remote origin/batter-icons

git checkout ups-icons-support

git rebase --onto master~1 HEAD~1 ups-icons-support

git branch -D --remote origin/master origin/ups-icons-support

git rebase --onto master~2 HEAD~1 ups-icons-support

git log --oneline --decorate --all --graph * c49c5e2 (ups-icons-support) XFCE-powemanager-UPS-icons | * 7ca1226 (HEAD, master) 96 support | * 66c295a folders and index for panel folder |/ * c4ca2a7 1.3.1 * c49c5e2 (ups-icons-support) XFCE-powemanager-UPS-icons | * 7ca1226 (HEAD, master) 96 support | * 66c295a folders and index for panel folder |/ * c4ca2a7 1.3.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM