简体   繁体   English

用git repo覆盖目录

[英]Overlay a directory with a git repo

I have a git repo that has files in directories. 我有一个git repo在目录中有文件。

I have a directory on my Linux box that has similar files from an old version that came from somewhere. 我的Linux机器上有一个目录,其中包含来自某个地方的旧版本的相似文件。

The Linux box also has thousands of important files that cannot be moved, copied or deleted and are not managed by git. Linux盒中还有成千上万的重要文件,这些文件无法移动,复制或删除,也不由git管理。

I need a command that will download/checkout/clone (I dont care) the git files from that repo and overwight any existing files that are older and/or create them if they do not exist without deleting the non managed data. 我需要一个命令来下载/签出/克隆(我不在乎)该仓库中的git文件,并覆盖所有较旧的现有文件和/或在不删除非托管数据的情况下创建它们(如果不存在的话)。

Nothing I've tried works, How do you do this ? 我没有尝试过任何工作,您如何做到这一点?

Thanks. 谢谢。

For overwriting files if they are older and creating new ones if they do not exist, I think you need to use rsync . 如果要覆盖较旧的文件并创建不存在的新文件,我认为您需要使用rsync There are many guides online. 在线上有很多指南。 rsync also has a --dry-run option to test the effect of the command you are running. rsync还具有--dry-run选项来测试您正在运行的命令的效果。

So you want to end up with a git repo of your latest version, but with a ton of extra files that you don't want git to manage? 因此,您想以最新版本的git repo结尾,但又拥有大量不希望git管理的额外文件吗? This might not be a good idea because reasons, but I'm going to go ahead anyway. 由于某些原因,这可能不是一个好主意,但是无论如何我都会继续。

Off the top of my head, so be careful: 离开我的头顶,所以要小心:

You could try git init on the current directory. 您可以在当前目录上尝试git init That will start git managing the directory, but everything will be "new" to git. 这将开始git管理目录,但是一切对git都是“新的”。

Next, git add remote to add your existing repo as a remote. 接下来, git add remote将您现有的仓库添加为一个远程仓库。 This will give you access to the latest git state without changing the working directory. 这将使您无需更改工作目录即可访问最新的git状态。

Then, git reset origin/master --hard should cause any tracked files to be overwritten with the latest versions from origin . 然后, git reset origin/master --hard应该使所有跟踪的文件都被origin的最新版本覆盖。 If you have files that are newer on your local filesystem, they will be overwritten! 如果您的本地文件系统上有较新的文件,它们将被覆盖! So watch out! 所以小心!


(But you may want to reconsider the whole thing. I would be happier with a fresh checkout of my project on the Linux box, in another directory, and keep the old version separate) (但是您可能想重新考虑整个事情。我会很高兴在Linux框的另一个目录中对我的项目进行新签出,并将旧版本分开保存)

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

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