Home > Net >  Cannot figure out specific Git syntax to "push" only a single file
Cannot figure out specific Git syntax to "push" only a single file

Time:01-14

It might not matter but I'm attached to the GitLab server with the SSH URL, rather than the HTTP(S) URL.

On the GitLab server, the path to the Project is (I'm gonna fake part of this for security purposes):
Group/Group/Project/subdir = Engineering/Bladelogic/Scripts/test

The closest I've come to success, in specifying a single file and getting a successful "push", is this:

$ git push origin development {commit-hash}:refs/{commit-hash}

But there are two problems:

  1. The above command (successfully) pushes everything that is presently committed and not yet pushed, rather than only the 1 file whose hash I specified.

  2. Even though it effectively pushes something, I still get the following screen-output, which includes the partial errors indicated below:

Counting objects: 17, done.  
Delta compression using up to 2 threads.  
Compressing objects: 100% (10/10), done.  
Writing objects: 100% (12/12), 1.19 KiB | 0 bytes/s, done.  
Total 12 (delta 4), reused 0 (delta 0)  
remote: error: refusing to create funny ref 'refs/62ce94830fa2753ef8ca3bb28d74dbe0cea39ead' remotely  
To git@<FQDN>:Engineering/Bladelogic/Scripts.git  
   9e722dd..62ce948  development -> development  
 **! [remote rejected] 62ce94830fa2753ef8ca3bb28d74dbe0cea39ead -> refs/62ce94830fa2753ef8ca3bb28d74dbe0cea39ead (funny refname)**  
**error: failed to push some refs to '[email protected]:bts-tools-engineering/tssa/BladeLogic-Scripts.git'**  

Is there a way to push only 1 presently-committed file and, if so, what am I doing wrong?

CodePudding user response:

There is no way to push only a single file. Git's protocol is designed around finding a set of commits and tags that are in common and sending the objects that one side has and not the other. That necessarily involves walking the history, which practically requires commits or tags.

If you want to make a changes to only a single file, you can put those changes in a separate commit and push only that. For example, if you want to create a new commit out of the state of file foo on branch branch, you could do git checkout branch:foo and then commit, which would create a commit that contained only that file.

But as for pushing just a single file, that's not possible. A tag or commit is going to be needed.

CodePudding user response:

If you really want to push just one file, tag that file and push the tag:

git tag myfile master:path/to/that.file
git push origin myfile

and then people fetching that tag will get just the one file -- which Git's convenience commands won't really know what to do with, but Git itself? Sure.

  •  Tags:  
  • Related