git squash followed by push retransmits data
I want to git-push a directory full of b开发者_运维问答inary data to a remote server.
As this may take days, I commit locally and push one file at a time (if I commit everything at once and push, if the transfer is interrupted, it has to be restarted from the beginning, right?).
When everything is transferred, I want to squash all these commits into one. If I squash locally and then push, all the data is being transmitted again! which defeats the purpose of my strategy.
Maybe I could log into the remote, and repeat the squash operation remotely, but is there a better way of doing what I want to do. How to inform git that all the sensible data is already on the server?
First, binaries are not best managed in a VCS ;)
Second, if you must, you could setup a hook on the remote repo to perform the squash when receiving a certain commit (like a push containing nothing but a special file, validating that all the previous commits can be squashed).
I am not sure about the exact implementation, but it seems any solution involving a git squash would have to take place both locally and on the remote side, to ensure similar history.
And that would be very safe if there are other commits from other contributors to said remote repository. Then the history would be impossible to synchronize correctly between your local repo and what would have been done on the remote side...
The only other course of action after such a special push followed by a squash on the remote side would be to rename your current branch, and to pull the remote branch in order to reset the local version of said branch to what is on the remote side.
I'm not sure but I think git won't transmit the objects if it have them already. Technically the commit doesn't contains your binary objects but only a referece to a tree which contains references to objects. Each object as an unique id (the SHA) so it should know that it had already them or not. So normally there is no need to send a second time the binary objects.
Just try it, and that should work as you want without doing anything.
精彩评论