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

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?

  • Git conflicted copy error while cloning a repository
  • Git: Only push private config file to test repository and not to github?
  • Ruby “bundle install” error on Openshift
  • need to use git behind firewall: trying ssh tunneling
  • How to configure 'git diff' to use emacs diff
  • egit - not authorized
  • Does maven-release-plugin push tags to remote Git repository?
  • setup git to ignore index.php in root folder only and not all index.php files in subfolders
  • Remove spurious commit parent pointer
  • Git error: Malformed input or input contains unmappable chacraters
  • What is Tracked files and Untracked files in the context of GIT?
  • Can't cherry pick (error)
  • 4 Solutions collect form web for “How can I push one Git commit without an earlier one?”

    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.

    What you can do is move the previous commit to a (temporary) branch, and cherry-pick your new commit to the master. 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 both your new commits. You can then later pick your previous one back to master:

    git cherry-pick temp_branch^
    git branch -D temp_branch
    

    After doing this, your master branch will contain the same two commits as you started with, but in the opposite order.

    just do another clone and push your bug fix from there.

    Our shop uses personal branches extensively. Basically the process would go like this:

    Given that you are currently on the master branch

    git checkout -b bug_fix_name_that_I_dont_want_to_commit
    

    The above creates a branch and checks it out…this is where you put the commits that you are not ready to push.

    Now you should be able to make commits to the current branch without affecting the master branch.

    When you’re ready to publish/push that one commit, just do:

    git push origin master
    

    and your other commits will not go to the origin repository.

    When you’re ready to incorporate the “bug fix” into the master branch, checkout the master branch and do;

    git merge bug_fix_name_that_I_dont_want_to_commit
    

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

    Git Baby is a git and github fan, let's start git clone.