Benjamin
Benjamin

Reputation: 2123

Push single outgoing commit in TFS Git

I have multiple unsynced, outgoing commits on my branch. I want to push one of them to my online repo, while I want to wait with pushing others (they're part of a larger process).

If you look at the screenshot below, how can I push only the first commit?

enter image description here

Upvotes: 3

Views: 3861

Answers (2)

Alexey Andrushkevich
Alexey Andrushkevich

Reputation: 6172

There is no simple way of doing that. I don't know how to do this from Visual Studio, but here is below the way how this can be done from command line using git utility.

Let's assume that your main branch has name "master" and you are currently checked in to it.

  1. Create a temp branch from your master:

    git checkout master
    git branch temp
    
  2. Reset master branch to origin/master so that to return it to the initial state when it didn't have your commits yet:

    git reset --hard origin/master
    
  3. Get all commits from remote master to synchronize your local and remote "master" branches. This step is necessary if there are commits you don't have yet in your local copy e.g. smbd else pushed while you were working locally. Anyway it worth to do it just to make sure:

    git pull origin master
    
  4. Now you can cherry-pick your last commit to master:

    git cherry-pick <hash_of_last_commit_in_temp_branch>
    
  5. Now you can push this commit to remote:

    git push origin master
    
  6. Now merge the rest of your commits from temp branch back to master branch:

    git merge temp
    
  7. And finally remove temp branch:

    get branch -d temp
    

That's it.

Upvotes: 2

Giulio Vian
Giulio Vian

Reputation: 8343

There is no simple way and Visual Studio 2013 Git integration offers no help; I would use Git command line or similar.

You should create a new branch to park all the commits, switch to the current branch (is it master?), reset it to match TFS status (i.e. origin) and cherry-pick the commits you want to apply and push.

Upvotes: 1

Related Questions