19

I'm using Git 1.7.4.1. I want to push commits I did on one folder to my remote repo. How do I push only changes from one folder to my remote repo? All the documentation I've found only lists how to push the entire repo ...

davea-mbp2:systems davea$ git push origin trunk
Password: 
To http://dalvarado@mydomain.com/systems.git
 ! [rejected]        trunk -> trunk (non-fast-forward)
error: failed to push some refs to 'http://dalvarado@mydomain.com/systems.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

The conflicts I'm being warned about do not apply to the folder that I want to push. Any help is appreciated, - Dave

Dave
  • 8,667
  • 25
  • 72
  • 90

4 Answers4

4

Git works by pushing entire commits. Either rebase interactively to isolate your changes to the directory you are interested in., or make a submodule for it.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
3

Git is not like subversion. The short answer is, you can't.

You should consider rebasing your change (only the one relevant) against the remote

git rebase -i origin/trunk

should get you underway. Be sure to read the comments and instructions along the way. There is also man git-rebase of course.

In the end, when you are satisfied with the result, you can either create a new branch from there

 git checkout -b rebased HEAD

or you can opt to make it your new master. I'll leave it up to you how to manage your branches locally (because you didn't tell us about them).

Pushing woud then be easy with

 git push origin trunk
sehe
  • 374,641
  • 47
  • 450
  • 633
1

git's unit of work is the commit. If you want to push changes to one directory but not others, those changes need to be separate commits.

If you haven't pushed these changes elsewhere yet, you can try an interactive rebase to make your commits look the way you need. See the git-rebase man page and this chapter in the Git community book for more details.

Mike Mazur
  • 2,509
  • 1
  • 16
  • 26
0

The error that you report is not reporting conflicts - you only get conflicts locally when merging (e.g. as part of a git pull). That error is just refusing to update the remote branch with your commit, since your commit doesn't include the history of the branch you're trying to push to. Typically that means that someone else has pushed some divergent development to that branch and you need to pull or rebase - there's more on that here: How git works when two peers push changes to same remote simultaneously

However, to answer your question directly, commits always represent the complete state of the tree, so you just need to create a commit which only has the changes in the subdirectory of interest. Just change into that subdirectory and use git add to stage the files that you've changed in there. Then, when you commit, make sure that you don't use the -a parameter, otherwise all the changes in your repository will be introduced into that commit.

Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327