push - Pushing git subtree changes to upstream repository fails -
i'm trying ensure git's subtrees work me before incorporate project. encountered problem when pushing subtree changes upstream repository.
the setup have 2 repos, sub
, main
, , main
includes sub
repo subtree
.
then following:
- initialize both repos initial commit.
- update
sub
repo directly (i.e. outside ofmain
). - update
sub
repo withinmain
repo. - split changes
sub
(usinggit subtree split
) separate branch, checkout. - attempt push upstream
sub
repo. naturally, push rejected because lose direct updatesub
. - pull new change
sub
repo. - attempt push upstream
sub
repo. time, should work, doesn't.
i've written script encapsulates problem. i'm using git version 1.8.2.1 subtree
module enabled. here's script:
#!/bin/bash echo -n "wiping old repositories..." rm -rf main sub sub-home echo "done" echo -n "initializing main , sub repositories..." mkdir sub-home ( cd sub-home ; git init -q --bare ) git clone sub-home sub > /dev/null 2>&1 ( cd sub ; echo subfile > subfile ; git add subfile ; git commit -qm "adding root-level file sub-project" ; git push -q origin master ) mkdir main ( cd main ; git init -q ; echo file > file ; git add file ; git commit -qm "adding root-level file main-project" ) echo "done" echo -n "adding sub project subtree main project..." wd=$pwd ( cd main ; git remote add sub-remote file://$wd/sub-home ; git subtree add -p sub sub-remote master >/dev/null 2>&1 ) echo "done" echo -n "committing sub-project directly..." ( cd sub ; date > the-date ; git add the-date ; git commit -qm "adding the-date sub-project" git push -q origin master ) echo "done" echo -n "committing sub-project within main project..." ( cd main ; echo 'subfile what?' > sub/subfile ; git add sub/subfile ; git commit -qm "changing sub-project within main project" ) echo "done" cd main git subtree split -q -p sub -b split-branch >/dev/null git checkout -q split-branch echo -e "\npushing main subtree sub project, should fail:" git push sub-remote master echo -e "\nbut if pull first..." git pull -q --no-edit sub-remote master echo "...then push *should* work (but doesn't):" git push sub-remote master cd ..
and here's output:
$ ./test.sh wiping old repositories...done initializing main , sub repositories...done adding sub project subtree main project...done committing sub-project directly...done committing sub-project within main project...done pushing main subtree sub project, should fail: file:///tmp/git/sub-home ! [rejected] master -> master (fetch first) error: failed push refs 'file:///tmp/git/sub-home' hint: updates rejected because remote contains work hint: not have locally. caused repository pushing hint: same ref. may want first merge remote changes (e.g., hint: 'git pull') before pushing again. hint: see 'note fast-forwards' in 'git push --help' details. if pull first... ...then push *should* work (but doesn't): file:///tmp/git/sub-home ! [rejected] master -> master (non-fast-forward) error: failed push refs 'file:///tmp/git/sub-home' hint: updates rejected because pushed branch tip behind remote hint: counterpart. check out branch , merge remote changes hint: (e.g. 'git pull') before pushing again. hint: see 'note fast-forwards' in 'git push --help' details.
further git pull
commands (from split-branch
branch of main
) "already up-to-date".
the thing that's confusing me that, far can tell, git push
command should giving upstream repo fast-forward commit, demonstrated following git log
output:
$ ( cd main ; git log ) commit 357fe9fb42f5d122338940eb4f22d3ca9d276318 merge: 472904f cb5d1d3 author: jeff terrell <jeff.terrell@acm.org> date: fri apr 19 16:03:03 2013 -0400 merge branch 'master' of file:///tmp/git/sub-home split-branch commit 472904f432c3a0a89acde02691b8281ac5246fd1 author: jeff terrell <jeff.terrell@acm.org> date: fri apr 19 16:03:02 2013 -0400 changing sub-project within main project commit cb5d1d34ce56374f78c98c5b3f3daa314907b62d author: jeff terrell <jeff.terrell@acm.org> date: fri apr 19 16:03:02 2013 -0400 adding the-date sub-project commit 7d1942203d30e0d9e8663517e6d594545bc50640 author: jeff terrell <jeff.terrell@acm.org> date: fri apr 19 16:03:02 2013 -0400 adding root-level file sub-project $ (cd sub ; git log ) commit cb5d1d34ce56374f78c98c5b3f3daa314907b62d author: jeff terrell <jeff.terrell@acm.org> date: fri apr 19 16:03:02 2013 -0400 adding the-date sub-project commit 7d1942203d30e0d9e8663517e6d594545bc50640 author: jeff terrell <jeff.terrell@acm.org> date: fri apr 19 16:03:02 2013 -0400 adding root-level file sub-project
here questions (finally):
- why push rejected?
- what can it? (if using
--force
option answer, how can not doing destructive?) - is there better way use
subtree
module avoid problem? (note: i'm not willing use submodules.)
your problem not related git subtree
. having problems old tricky git ui. in case git push
. assumed syntax follows git pull
. rather naive – using git ;).
you push output tells wrong here:
to file:///tmp/git/sub-home ! [rejected] master -> master (non-fast-forward)
git pull sub-remote master
fetches , merges head of sub-remote/master
checked-out branch, expected. git push sub-remote master
not push head of checked-out branch sub-remote/master
. push branch of same name. in case master
, can see in output above.
from git push
(syntax git push <repsitory> <refspec>
):
the format of
<refspec>
parameter optional plus +, followed source ref<src>
, followed colon:
, followed destination ref<dst>
. used specify<src>
object<dst>
ref in remote repository updated.the
<dst>
tells ref on remote side updated push. arbitrary expressions cannot used here, actual ref must named. if:<dst>
omitted, same ref<src>
updated.
so command looking git push sub-remote splitbranch:master
. why not using git subtree push
in first place?
Comments
Post a Comment