Git Subtree forgery always fails

Trying to use a git subtree to share shared library files across multiple projects. Here's the problem I'm facing.

1) Add a subtree, so the "lib" subdirectory of my project comes from the lib-dk repository.

$ git subtree add --prefix=lib --squash git@bitbucket.org:dwknight/lib-dk.git master

      

2) Make changes to files in "lib"

3) commit changes to the main project repo

$ git commit -am "update project"

      

4) push updates to the main project repo

$ git push origin master

      

5) move the changes to "lib" back to the "lib-dk" repo

$ git subtree push --prefix=lib git@bitbucket.org:dwknight/lib-dk.git master
git push using:  git@bitbucket.org:dwknight/lib-dk.git master
To git@bitbucket.org:dwknight/lib-dk.git
 ! [rejected]        f455c24a79447c6e3fe1690f5709357b7f96828a -> master (non-fast-forward)
error: failed to push some refs to 'git@bitbucket.org:dwknight/lib-dk.git'
hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

      

6) I get this rejection even though nothing has changed in the lib-dk repo. When I try to pull it out, it acts like something, but I can update it. However, the push continues to deviate.

+3


source to share


2 answers


When I try this without the --squash

before option git subtree add

, it works. I think, as the commentator said, --squash

plays in a useless way.



+2


source


You may need git add -A .

, then git commit

, rather thangit commit -am <message>

since -A

in git-add

will do:

   -A, --all, --no-ignore-removal
       Update the index not only where the working tree has a file matching <pathspec> but also where the
       index already has an entry. This adds, modifies, and removes index entries to match the working
       tree.

       If no <pathspec> is given when -A option is used, all files in the entire working tree are updated
       (old versions of Git used to limit the update to the current directory and its subdirectories).

      



on the other hand, -A

in git-commit

will do (not very detailed on the man page):

   -a, --all
       Tell the command to automatically stage files that have been modified and deleted, but new files
       you have not told Git about are not affected.

      

this one might be helpful. The author named it git add -A .

explicitly.

0


source







All Articles