简体   繁体   English

使用 git 合并手动复制目录中的更改

[英]Using git to merge changes in a manually-copied directory

At work I keep a backup of a large directory on our remote VPS using git.在工作中,我使用 git 在我们的远程 VPS 上保留一个大目录的备份。 Because I live in a very remote town with poor, expensive internet, I cannot copy this repo over the internet.因为我住在一个非常偏远的小镇,互联网很差,价格昂贵,我无法通过互联网复制这个 repo。 Instead, when I started working from home, I brought a copy of the directory on an external drive (unfortunately without the ".git" subdirectory).相反,当我开始在家工作时,我在外部驱动器上带了一份目录副本(不幸的是没有“.git”子目录)。

I have made about 10kb worth of changes to files in my home copy of the directory.我对目录的主副本中的文件进行了大约 10kb 的更改。 I would like to merge these in to the git repo on the remote server without transferring the whole directory over the internet.我想将这些合并到远程服务器上的 git 存储库中,而无需通过 Internet 传输整个目录。

Steps so far:到目前为止的步骤:

git init
git add .
git commit -m "initial"
git remote add VPS [SSH_ADDRESS]
git remote show VPS   # successfully connects to remote

Now I'd like to merge the 10kb of changes I've made locally without transferring the GB of data that are unchanged.现在我想合并我在本地所做的 10kb 更改,而不传输未更改的 GB 数据。

Steps I've tried but failed:我尝试过但失败的步骤:

git push VPS   # can't because there are non-integrated remote changes
git fetch VPS  # starts downloading GBs of data

Not sure where to go next.不知道接下来去哪里 go。

A hacky approach that tries to transfer as little data as possible, not using git's transport methods, that may or may not work:一种尝试传输尽可能少的数据而不使用 git 的传输方法的 hacky 方法,它可能有效,也可能无效:

  • generate patches of your local work ( git format-patch )生成本地工作的补丁( git format-patch
  • compress those patches ( tar or zip )压缩这些补丁( tarzip
  • send them to to the remote server ( scp or rsync )将它们发送到远程服务器( scprsync
  • login to the remote server ( ssh )登录远程服务器( ssh
  • apply the patches ( unzip / tar followed by git apply ), fix conflicts and edit the history to your liking应用补丁( unzip / tar后跟git apply ),修复冲突并根据自己的喜好编辑历史

This will leave your local copy out of sync, as before.这将使您的本地副本像以前一样不同步。


Assuming that the "GBs of data" are large files and not many small changes/files, you can circumvent having to store them in the actual git repo.假设“GB 数据”是大文件而不是很多小的更改/文件,您可以避免将它们存储在实际的 git 存储库中。

There are multiple approaches to this problem, of which I have tried neither, but here are some pretty well known:有多种方法可以解决这个问题,我都没有尝试过,但这里有一些众所周知的方法:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM