Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I push one Git commit without an earlier one?

Tags:

git

I have made a git commit but I have not pushed. And I am now working on a new bug fix, which should not touch the same files as the first commit.

Is it possible for me to commit this bug fix AND git push only this commit?

like image 281
n179911 Avatar asked Oct 28 '09 21:10

n179911


Video Answer


1 Answers

All of the commits leading up to a particular commit are what defines that new commit.

That is, if you have a master → dev → bugfix as shown in the image below:

master → dev → bugfix http://img.skitch.com/20091029-tbffrg53q73mdipiwcr3g2ywuh.png

you can push dev alone but not bugfix alone, but the definition of bugfix includes dev, so dev has no meaning without bugfix

However, if you build this bugfix out as a feature branch, you'd have something that looked more like this:

feature branch http://img.skitch.com/20091029-t3w5qk3bhj3ftx1d9xnk32ibkb.png

You could still retroactively do that (create a new branch from origin/master, cherry-pick the change, and then git reset --hard HEAD^ on your development branch to get the bugfix change off of it).

Once that's complete, you can forward-port your dev branch with a simple git rebase master and it'll look like this:

new master http://img.skitch.com/20091029-1ts3enwsmsr29imcu7tyk75ett.png

In practice, starting bug fixes from a branch will make this kind of thing a lot easier in general.

like image 192
Dustin Avatar answered Sep 28 '22 04:09

Dustin