自动存储 [英] Automatically stashing

查看:115
本文介绍了自动存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链中的最后一个链接:存储和reflog rel =noreferrer> http://ftp.newartisans.com/pub/git.from.bottom.up.pdf 建议经常存放您的正在进行的作品快照。作者甚至建议您可以使用cron作业来定期存放您的作品,而无需手动存储。


存储的美妙之处在于,它可以让你将不显眼的版本控制应用于你的工作
过程本身:即每天工作树的各个阶段。如果你愿意的话,你甚至可以定期使用
隐藏,像下面的快照脚本一样:

  $猫<< EOF> / usr / local / bin / git-snapshot 
#!/ bin / sh
git stash&& git stash apply
EOF
$ chmod + x $ _
$ git snapshot

没有理由不能每小时运行一次cron作业,并且每周或每月运行reflog expire命令。

这种方法的问题是:

$ ol
如果你的工作拷贝没有变化,那么git stash apply将会导致你的最后一个存储被应用于你的工作副本。

  • 执行cron作业的时间与工作副本上的用户之间可能存在争用情况。例如,git stash运行,然后用户打开文件,然后执行脚本的git stash apply。

  • 有没有人有建议使这种自动存储工作更可靠?

    解决方案

    我确实不会设置自动存储描述在那篇文章中, 。

    我更愿意使用存储器,因为它是有意使用的,我在那里刻意存储和应用更改。对于定期备份,我使用适当的备份解决方案。在我看来,Git不能替代备份解决方案。


    The section Last links in the chain: Stashing and the reflog in http://ftp.newartisans.com/pub/git.from.bottom.up.pdf recommends stashing often to take snapshots of your work in progress. The author goes as far as recommending that you can use a cron job to stash your work regularly, without having to do a stash manually.

    The beauty of stash is that it lets you apply unobtrusive version control to your working process itself: namely, the various stages of your working tree from day to day. You can even use stash on a regular basis if you like, with something like the following snapshot script:

    $ cat <<EOF > /usr/local/bin/git-snapshot
    #!/bin/sh
    git stash && git stash apply
    EOF
    $ chmod +x $_
    $ git snapshot
    

    There’s no reason you couldn’t run this from a cron job every hour, along with running the reflog expire command every week or month.

    The problem with this approach is:

    1. If there are no changes to your working copy, the "git stash apply" will cause your last stash to be applied over your working copy.
    2. There could be race conditions between when the cron job executes and the user working on the working copy. For example, "git stash" runs, then the user opens the file, then the script's "git stash apply" is executed.

    Does anybody have suggestions for making this automatic stashing work more reliably?

    解决方案

    I certainly wouldn't set up automatic stashing as described in that (otherwise excellent) article, for exactly the reasons you cite.

    I prefer to use the stash as it is intended to be used, where I deliberately stash and apply changes as I'm working. For periodic backups, I use a proper backup solution. In my opinion, Git is not a substitute for a backup solution.

    这篇关于自动存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆