本地 Git 自动保存
我希望本地 GIT 是我的主目录,以实现每五分钟自动保存到存储库。
我有两个问题:
- 这样做明智吗?
- 如何编写一个脚本来为 Linux 主目录中的一组指定目录实现此功能?
目的是自动捕获我的主目录中所有重要文件的所有历史记录,而无需我进行任何输入。每当我搞砸的时候我都可以使用这个。
I would like a local GIT is my home directory to implement autosave to the repository that happens every five minutes.
I have two Questions:
- Is this s sane thing to do?
- How does one go about writing a script that implements this functionality for a specified set of directories in the home directory on linux?
The aim is to capture all the histories all the important files in my home directory automatically without any input from me. I can use this whenever I screw-up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
理智都是相对的!
我想这取决于你备份的原因。如果是因为硬件故障,那么这将不起作用,因为存储库位于同一文件夹(/home/)中,因此如果文件夹消失,存储库也会消失。当然,除非您将其推送到另一台计算机上的存储库作为实际备份。
我们确实使用 git 来存储重要的东西,尤其是研究论文和 PDF,因此我们可以轻松共享它们。
您将编写一个经常运行脚本的
cron
作业。基本上,您将编写一个简单的bash
脚本,定期在文件夹中执行git commit -a -m "commit message"
。棘手的部分是对创建的新文件执行 git add 以便跟踪它们。您可能需要执行git status
并在脚本中解析其输出以查找新文件,然后git add
该列表。 Python 可能是最简单的方法。然后你用cron 注册。
Google 是你的朋友,有很多关于如何用
cron
注册脚本的例子。Sanity is all relative!
I guess it depends on why you are backing up. If it's for hardware failure, then this won't work because the repository is in the same folder (/home/) so if the folder goes, the repo goes. Unless of course you are pushing it to a storage repo on another machine somewhere as the actual backup.
We do use git to store important things, especially research papers and PDF's, so we can easily share them.
You would write a
cron
job that runs a script every so often. Basically you would write a simplebash
script that does agit commit -a -m "commit message"
periodically in your folder. The tricky part is doing thegit add
on the new files that were created so they are tracked. You will likely need to do agit status
and parse the output from it in your script to find the new files, thengit add
that list. Python may be the easiest way to do that. Then you register that withcron.
Google is your friend here, there are plenty of examples on how to register scripts with
cron
.编写一个 shell 脚本,该脚本将进入您想要的每个目录并运行
,然后使用 cron 每 5 分钟运行该脚本。
Write a shell script that would enter each directory you want and run
and then use cron to run the script each 5 minutes.
编写一个 shell 脚本来执行以下操作:
在 cron 中安排此脚本。
Write a shell script to do the following
Schedule this script in cron.