tags:

views:

63

answers:

2

Hi, i am working in a project and as i make one change i commit it. Then, after commiting 3 or 4 changes i push it all.

What i would like to do is to push just one of those revisions that i have locally. can i do that? How?

Thanks

+4  A: 

Try working in a local 'work' branch. This has advantages such as you can switch to a different branch if you get called to work on say, a bug.

When you're ready to push: git checkout master, git pull, git merge work, git push, will be your normal flow.

However, you can cherry-pick commits from your work branch to the master, that way only those commits will be pushed.

git checkout master
git cherry-pick <id of commit you want>
git push

You could likely do this even now.

git checkout -b work
git log (and look for the IDs of the commits you want)
git checkout master
git reset --hard HEAD~3 (remove last 3 commits from master)
git cherry-pick <ID of commit you want>
git push
Graham Perks
Using gitk, it's very easy to do cherry-picking.
gawi
pabloruiz55, note the last steps I posted should accomplish what you need.
Graham Perks
+2  A: 

I'm not quite sure what you want to do. If you have 4 unpushed commits and you only want to push the first of those commits, you could pass its ref to git push. If you want to push, say, the third of those commits, but not the first or the second, you will have problems. You can't really do that. (Well OK, you probably can, but then it would be disconnected from the rest of the tree).

If you simply want to collapse your four commits into a single commit before pushing, you might want to work in a separate branch and use squash merges. You can't push a commit to the remote repository until it exists in your local repo. You can't synthesize a commit as part of the push (as far as I know).

Daniel Yankowsky
Yes, what i want to do is to push the first one (the oldest one) Would it be git push 1234567890 where 1234567890 is the revision number?
pabloruiz55
I think you need to use something like `git push 1234567890:master`. Substitute the appropriate branch name. I just checked the git manpage, and I'm flabbergasted that this usage is not listed as an example.
Daniel Yankowsky