简体   繁体   English

使用git抓取/更新仓库中的特定文件到目录

[英]Using git to grab/update specific files in a repo to a directory

I'm very new to using git, so I understand this may seem like a simple question or one that's been asked before, but I can't word it to get an answer. 我对使用git很陌生,所以我理解这似乎是一个简单的问题,也可能是以前问过的问题,但是我无法说出它来得到答案。 Anyway. 无论如何。

My thoughts are that I code on my laptop, at the minute when I want to put my program on a server, which happens to be the raspberry pi sitting under my desk, I simply SCP to it. 我的想法是,当我想将程序放在服务器上的那一刻,我在笔记本电脑上编码,这恰好是坐在桌子下面的树莓派,我只是对它进行SCP检查。

I was wondering how using git I can update files in a directory. 我想知道如何使用git更新目录中的文件。 For example all I need to run the bot is two files. 例如,我需要运行的机器人是两个文件。

pi@raspberrypi:~/gitDiscordBot/Jarvis $ ls -a
.  ..  bot.py  .git  .gitignore  Insult.txt  README.md

This is the result from simply cloning the repo, however I don't need most of these files/directories. 这是简单地克隆仓库的结果,但是我不需要大多数这些文件/目录。 I don't need .git, .gitignore or README.mb. 我不需要.git,.gitignore或README.mb。 I also need to keep a credentials.json file in tact that isn't in the repo as it contains sensitive data accessed by bot.py. 我还需要保持一个完整的凭据文件(不在存储库中),因为它包含bot.py访问的敏感数据。

What's the best way to make some sort of 'update' function that simply grabs the files bot.py and any other files that I need, in this case Insult.txt, replace the existing copies and keep credentials.json untouched, without other redundant git files. 进行某种“更新”功能的最佳方法是什么,该功能可以简单地获取文件bot.py和我需要的任何其他文件(在本例中为Insult.txt),替换现有副本并保持凭据.json不变,而无需其他冗余git文件。

I understand, this may not be the best approach, I'm looking to find the best approach, so please feel free to contradict what I'm saying, I don't know if keeping the git repo is a good thing for example. 我了解,这可能不是最佳方法,我正在寻找最佳方法,所以请随时与我所说的相矛盾,例如,不知道保存git repo是否是一件好事。 But all I simply need is the latest versions of bot.py and the other files in a directory so I can run them on my pi. 但是我所需要的只是bot.py的最新版本以及目录中的其他文件,因此我可以在pi上运行它们。

Such that 这样的

$ ls -a
. .. bot.py Insult.txt credentials.json

first of all, welcome to git! 首先,欢迎来到git!

.git and .gitignore files are for git to function. .git.gitignore文件使git起作用。 You cannot remove them. 您无法删除它们。 They are tiny in size and they are not "copied" when you do commit and sync. 它们很小,在提交和同步时不会“复制”。 So, they should not be problem to your application. 因此,它们应该不会对您的应用程序造成问题。

For your sensitive file, credentials.json , you can put it into .gitignore file. 为了您的敏感文件, credentials.json ,你可以把它变成.gitignore文件。 This way, it won't be included in any commits. 这样,它将不会包含在任何提交中。 There will be only one copy of it in you machine. 您的计算机中将只有一个副本。

This approach is good and works well. 这种方法很好,效果很好。 But, I think in your case you need rsync rather than git. 但是,我认为在您的情况下,您需要rsync而不是git。 From the official manuals page: 从官方手册页面:

Rsync is a fast and extraordinarily versatile file copying tool. Rsync是一种快速且用途广泛的文件复制工具。 It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. 它可以通过任何远程Shell在本地复制到另一个主机,或从另一个远程复制到另一个rsync守护程序。 It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. 它提供了许多选项来控制其行为的各个方面,并允许非常灵活地指定要复制的文件集。

You can learn more about it here . 您可以在此处了解更多信息。

Hope this helps. 希望这可以帮助。

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

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