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

I made a git commit , but I did not click. And now I'm working on a new bug fix that should not touch the same files as the first commit.

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

+6
git
source share
4 answers

All commits leading to a specific commit determine what the new commits.

That is, if you have a wizard β†’ dev β†’ bugfix, as shown in the image below:

master β†’ dev β†’ bugfix http://img.skitch.com/20091029-tbffrg53q73mdipiwcr3g2ywuh.png

you can only click dev , but not bugfix , but the definition of bugfix includes dev , so dev doesn't make sense without bugfix

However, if you create this bugfix as a function branch, you will have something similar to this:

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

You can still do a retroactive action (create a new branch from origin/master , cherry-select this change, and then git reset --hard HEAD^ in the development branch to remove the error from it).

After that, you can redirect the dev branch with a simple git rebase master , and it will look like this:

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

In practice, the original bug fixes from the branch will make this much easier.

+7
source share

What you can do is transfer the previous commit to the (temporary) branch, and cherry select the new commit for the wizard. For example:

 # first commit your current work git branch temp_branch git reset --hard HEAD~2 git cherry-pick temp_branch git push 

Then temp_branch will contain your new commits. Then you can later choose your previous one:

 git cherry-pick temp_branch^ git branch -D temp_branch 

After that, your leading branch will contain the same two commits as you, but in the reverse order.

+6
source share

just make another clone and push back the bug fix.

0
source share

Our store makes extensive use of personal branches. Basically, the process will look like this:

Given that you are on the main branch

 git checkout -b bug_fix_name_that_I_dont_want_to_commit 

The above branch also validates it, this is where you put commits that you are not ready to push.

Now you can commit the current branch without affecting the main branch.

When you are ready to post / push this commit, simply do:

 git push origin master 

and your other commits will not be sent to the original repository.

When you are ready to include β€œbug fixes” in the main branch, check the master branch and run:

 git merge bug_fix_name_that_I_dont_want_to_commit 

I think this answers the question, but if not, just let me know!

0
source share

All Articles