[Kde-pim] Re: Pushing a single commit in git

Christian Mollekopf chrigi_1 at fastmail.fm
Mon Jan 3 22:59:06 GMT 2011


On Monday 03 January 2011 23:00:18 David Jarvie wrote:
> On Monday 03 January 2011 21:40:24 Christian Mollekopf wrote:
> > On Monday 03 January 2011 22:07:05 Torgny Nyblom wrote:
> > > On Monday 03 January 2011 20.47.09 David Jarvie wrote:
> > > > How can I push a commit for one specific file to the git repository?
> > > > I've committed various changes locally, but I currently only want to
> > > > push one of them to the kdepim repository. I've looked at git help
> > > > and several cheat sheets etc, but can't find how to do it.
> > > 
> > > As far as i know you cannot :( One reason to use local branches,
> > > something I always remember after the fact that needed one :)
> > 
> > just make "git stash" which will save all your uncommited changes, and
> > reset all files to the latest commit. You can then commit.
> > 
> > Afterwards reapply your changes with "git stash apply"
> 
> I've alread committed various changes, including the single one I want to
> push. Is there any way to create a new branch without any of my local
> commits, so that I can then apply the change to the single file in the
> local repository, and then push the change for that file only? Or would I
> have to download the whole repository again before making that change?

it is not completely straight forward, since this will rewrite your local 
history (which is not a problem as long as you don't have those branches 
shared already somewhere). So here is how it goes (i'll assume you are 
currently on the master branch):

-"git stash" to save your local uncommitted changes
-"git branch NEWBRANCHNAME" create a new branch which has all your commited 
changes
-then revert the current branch to state of the server, i usually use gitk for 
this (rightclick on the wanted commit, and then revert or reset).
This will delete all your commit from this branch (you still have them on 
NEWBRANCHNAME)
-then start gitk again with the --all option which will show all available 
branches
-cherry pick the wanted commit from NEWBRANCHNAME
-push it to the repository (you might have to update the branch first with a 
git rebase)
-then to cleanup switch to NEWBRANCHNAME, and make a "git rebase master" and 
afterwards "git stash apply" to reapply your uncommitted changes. The rebase 
will likely give some errors because of the same patch (which you 
cherrypicked) will be applied again, but you should be able to skip it in the 
resolve dialog.

The cherrypick method works of course only if you have a single commit for the 
change of that file. Otherwise you might find answers here:
http://stackoverflow.com/questions/307579/how-do-i-copy-a-version-of-a-single-
file-from-one-git-branch-to-another
http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-
git-merge


Generally I would suggest that you have a master branch, which you do not 
normally touch. The master should always represent the latest state of the 
remote repository.

So if you start working on something, create a branch, work on it. When you 
want to push something, go to master, updated it, switch to your working 
branch and rebase it on the latest master. You can then merge your 
workingbranch into the master and push the master branch to the repository 
(the workingbranch can then of course be deleted).

Thats at least how i do it. 
Correct me if I'm wrong, but I think this should work (to be completely save, 
commit your uncommited changes, and create a throwaway branch)

Cheers,

Chris
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list