Git puzzler - Working around `denying non-fast-for

2019-08-09 19:52发布

In my local git repository, I had essentially:

* commit A
|
* commit B (master) (origin/master)

I made some changes so it is now:

* commit A
|\
| * commit B (develop) (origin/master)
|
* commit C (master)

I would like the Git repo (hosted on beanstalkapp.com) to be updated to reflect this, and look like:

* commit A
|\
| * commit B (develop) (origin/develop)
|
* commit C (master) (origin/master)

How can I do this? git push fails with denying non-fast-forward refs/head/master. What are my options to work around this?

My repo hasn't been very organized, and I'd like to refactor it once and for all.

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-09 20:19
git checkout master
git merge origin/master strategy=ours
git push origin master

The 'ours' strategy ignores all changes made between commit A and B, and makes a "fake" merge (a merge in name only). git push then happily does a fast-forward commit between the old origin/master and the new master.

The result:

* commit A
|\
| * commit B (develop)
| |
* | commit C
| /
* commit D, but identical to C (master) (origin/master)
查看更多
虎瘦雄心在
3楼-- · 2019-08-09 20:23

Are you allowed to do a forced push?

Otherwise are you allowed to delete a branch? In that case you can just delete the old branch and push the new one, which is essentially the same as a forced push.

查看更多
登录 后发表回答