本地 Git 自动保存

发布于 2024-12-22 01:28:03 字数 193 浏览 1 评论 0原文

我希望本地 GIT 是我的主目录,以实现每五分钟自动保存到存储库。

我有两个问题:

  1. 这样做明智吗?
  2. 如何编写一个脚本来为 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:

  1. Is this s sane thing to do?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初心 2024-12-29 01:28:03

理智都是相对的!

我想这取决于你备份的原因。如果是因为硬件故障,那么这将不起作用,因为存储库位于同一文件夹(/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 simple bash script that does a git commit -a -m "commit message" periodically in your folder. The tricky part is doing the git add on the new files that were created so they are tracked. You will likely need to do a git status and parse the output from it in your script to find the new files, then git add that list. Python may be the easiest way to do that. Then you register that with cron.

Google is your friend here, there are plenty of examples on how to register scripts with cron.

箜明 2024-12-29 01:28:03

编写一个 shell 脚本,该脚本将进入您想要的每个目录并运行

git add .
git commit -m "new change"
git push

,然后使用 cron 每 5 分钟运行该脚本。

Write a shell script that would enter each directory you want and run

git add .
git commit -m "new change"
git push

and then use cron to run the script each 5 minutes.

じ违心 2024-12-29 01:28:03

编写一个 shell 脚本来执行以下操作:

1) git status --u=no  //It gives you the files which are modified
2) Iterate through the file list from step 1 and do git add <file>
3) git commit -m "latest change <date:time>"

在 cron 中安排此脚本。

Write a shell script to do the following

1) git status --u=no  //It gives you the files which are modified
2) Iterate through the file list from step 1 and do git add <file>
3) git commit -m "latest change <date:time>"

Schedule this script in cron.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文