LightCC
LightCC

Reputation: 11639

Git: Is there a way to push a commit only held by a tag, without pushing the tag?

Scenario:

  1. Create a tmp branch

  2. Commit some temporary changes

  3. Tag the commit tmptag

    x-x-x-y-y  <- master
         \
          z  <- tmp [tmptag]
    
  4. Delete the tmp branch

    x-x-x-y-y  <- master
         \
          z  <- [tmptag]
    

Now I have a commit, z that is being held only by a tag tmptag.

I understand that if you push tmptag to the remote (either by name or by pushing all tags), commit z will also be pushed.

Questions:

  1. Are there any other commands that will push z to the remote?

  2. Also, if specifically I push all branches, z will not be pushed, right?

Upvotes: 0

Views: 249

Answers (1)

torek
torek

Reputation: 487893

  1. Yes, anything that says ask the other Git to please set some name to point to the commit whose ID is z will transfer commit z. For instance:

    git push $(git rev-parse tmptag^{}):refs/heads/newbranch
    

    would ask the other Git to create branch newbranch pointing to the tagged commit. (The ^{} suffix is required if and only if tmptag is an annotated tag.) You could also use the raw hash ID, and something other than a branch name, provided the other Git allows you to push to that reference.

  2. Correct: since z is not reachable from a branch name, it will (at least normally1) not get sent.


1Each Git transport is responsible for collecting objects to send and sending them, and if some transport is weird or careless or something, it could collect up commit z and send it. The built in push transports (generally invoking git send-pack with --thin) won't do that, but it's interesting to consider a case where z is a base object in a pack, and some deltified object in the same pack also needs to be sent.

Upvotes: 3

Related Questions