Git: change HEAD
I have a repository on Bitbuket with two branches:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/ng-1
master
contains old tool code, and ng-1
- new.
What I want to do - is switch master
to ng-1
so when git pull
will be executed - it will pull code from "master"
- but with new code.
Let's say - I want "move" code from master
to ng-1
- and from ng-1
to master
.
As I googled - this can be done with:
$ git update-ref HEAD ng-1
Thus - "main default" branch will became ng-1
and master
will be saved as my "backup".
If something will go wrong - I'll can just do vice versa:
$ git update-ref HEAD master
Am I correct?
What I want to do - is switch master to ng-1
// Checkout the new branch
git checkout ng-1
... when git pull will be executed - it will pull code from "master" - but with new code
// Pull "old" changes - if ng-1 is forked from master no update should be pulled
git pull origin master
// Now you ng-1 contains the "new" code as well.
Found answer here:
https://stackoverflow.com/a/2862938/2720802
$ git fetch && git checkout ng-1
$ git branch
master
* ng-1
$ git merge -s ours master
Already up-to-date.
$ git checkout master
$ git merge ng-1
Already up-to-date.
$ git branch
* master
ng-1
$ git add -A
$ git commit -m "Merged"
$ git push origin
Seems all done.
I'd take a look at using SourceTree, a GUI that will help you visualise what you want to do and it's made by the same people who do BitBucket.
Answer wise what codeWizard said will do what you are after by the sounds of it.
链接地址: http://www.djcxy.com/p/94812.html上一篇: 选择合并之外的提交
下一篇: Git:改变HEAD