Git subtree export and re-import woes

∥☆過路亽.° 提交于 2019-12-05 18:47:18

I tried a git push -f which seems to have worked. Still would like to know what exactly happened and why.

The default behavior of git push is to try to push all branches to the current branch remote if you have same named branches locally and remotely. From the git push manual:

The special refspec : (or +: to allow non-fast-forward updates) directs git to push "matching" branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file---see below) and no push.default configuration variable is set.

In this case, since your current remote is C and you have both locally master and remotely C/master it will be pushed, and since the trees will not match at all the push will fail with the master -> master (non-fast-forward) message.

When you git pull to your branch it says up-to-date because you are pulling yo your current branch, which is up to date.

To modify this behavior of git push you need to setup the push.default value in your git config. Look for "push.default" in http://www.kernel.org/pub/software/scm/git/docs/git-config.html

My solution: upgrade git. :-)

Your test script succeeds for me, assuming the testA and testC directories already exist. I'm using the latest version of git (v1.8.2.1), so perhaps they fixed something since you posted this.

$ mkdir testA testC
$ ./test.sh 
Initialized empty Git repository in /tmp/git/testC/
Initialized empty Git repository in /tmp/git/testA/.git/
[master (root-commit) 3d5644d] adding files
 2 files changed, 2 insertions(+)
 create mode 100644 sub/subFile1
 create mode 100644 sub/subFile2
[master 398c203] add root level files
 2 files changed, 2 insertions(+)
 create mode 100644 fileA
 create mode 100644 fileB
Created branch 'split-branch'
57fe3e8fc226d854b623f11444d82dc77fd45682
Counting objects: 4, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 269 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
To ../testC
 * [new branch]      split-branch -> master
Branch cmaster set up to track remote branch master from C.
Switched to a new branch 'cmaster'
[cmaster 07c7c89] updated #2 in C
 1 file changed, 1 insertion(+), 1 deletion(-)
Counting objects: 5, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 285 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ../testC
   57fe3e8..07c7c89  cmaster -> master
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!