有没有办法阻止“git stash pop”从标记文件修改? [英] Is there a way with to prevent "git stash pop" from marking files as modified?

查看:112
本文介绍了有没有办法阻止“git stash pop”从标记文件修改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个git-hook来通过pyflakes和jshint扫描我的提交,并且在阅读Yipit关于为什么大多数pre-commit钩子都是坏的,我选择实现他的 git stash git stash pop 建议。



不幸的是, git stash pop 会将这些文件标记为'modified',这会导致我的IDE会在我回到那个页面时提醒我在磁盘上修改,从磁盘重新读取?然后它会问你确定要编辑这个缓冲区吗?最后是你确定要将这个缓冲区保存在修改后的文件中吗?



我很欣赏它为我所做的一切,但它问我关于功能性非

使用 touch 玩奇怪的猜谜游戏有一些方法可以防止出现 git stash pop 标记所有触摸的文件已更改?

解决方案

我不这么认为(时间戳已被修改,如 GIT:将本地更改添加到非当前分支中所述)例如)。

最简单的方法是将IDE配置为自动刷新。



对于Eclipse ,这将是设置刷新访问






另一种方法是保留另一个本地回购(其中没有本地修改所以不需要存储)。

您的预提交钩子仍然保留在您当前的仓库中。



您的钩子会使用您当前的索引(你已经添加了),但是其他工作树回购。

为此,您需要提交:

  git commit --work-tree = / path / to / other / local / repo -m我的提交消息

如果钩子没有失败,你可以有一个post-commit钩子(仍然在你当前的仓库中)转到另一个仓库,

  cd / path / to / other / local / repo 
git分支,更新它的(原始的)工作树。

--work-tree = / path / to / other / local / repo --git-dir = / path / to / other / local / repo / .git pull
work-tree 和 git-dir ,以便正常工作)。
这是一个简化的建议,因为它没有考虑到cu您正在使用的rrent分支(它假设只有一个分支'master')。

但是您可以检测分支并从那里调整钩子(使用正确的结账并切换到右分支)。

在其工作树的第二次回购更新后第二次回购可以作为一个原始的工作树,您的预提交钩子(您的第一个和当前回购)可以安全地运行。


I implemented a git-hook to scan my commits through pyflakes and jshint, and after reading Yipit's commentary on why most pre-commit hooks are broken, I chose to implement his git stash and git stash pop suggestions.

Unfortunately, git stash pop marks the files as 'modified', which then causes my IDE to warn me whenever I go back to that page " modified on disk. Reread from disk?" It then asks "Are you sure you want to edit this buffer?" and finally "Are you sure you want to save this buffer over a modified file?"

I appreciate everything it's trying to do for me, but it's asking me about functionally non-existent "changes".

Short of playing weird guessing games with touch is there some way to prevent git stash pop from marking all of the files it touched as changed?

解决方案

I don't think so (timestamp is altered, as mentioned in "GIT: Adding Local Changes to Non-Current Branch" for instance).

The easiest way would be configure your IDE to refresh automatically.

For Eclipse for instance, this would be the setting "Refresh on Access".


Another approach would be to keep another local repo (one where there is no local modification ever, so no need to stash).
Your pre-commit hook remains in your current repo.

Your hook would use your current index (what you have added), but the other work-tree repo.
For that, you would need to commit with:

git commit --work-tree=/path/to/other/local/repo -m "my commit message"

If the hook doesn't fail, you can have a post-commit hook (still in your current repo) go to the other repo, and pull the current branch, updating its (pristine) working tree.

cd /path/to/other/local/repo 
git --work-tree=/path/to/other/local/repo --git-dir=/path/to/other/local/repo/.git pull

(Note how your hook, which lives in your first repo, needs to specify work-tree and git-dir of the second repo, in order to work properly).
That is a simplified proposal as it doesn't take into account the current branch you are working on (it assumes only one branch 'master').
But you can detect the branch and adapt from there the hook (with the proper checkout and switch to the right branch).

After the second repo update of its working tree (by the post-commit hook of the first repo), that second repo is ready to serve as a pristine working tree against which your pre-commit hook (of your first and current repo) can safely operate.

这篇关于有没有办法阻止“git stash pop”从标记文件修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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