如何防止使用“假定不变”的git存储丢失更改位? [英] How to prevent git stash dropping changes to files with the "assume unchanged" bit?

查看:96
本文介绍了如何防止使用“假定不变”的git存储丢失更改位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些文件上使用了 git update-index --assume-unchanged 来保留我的更改以免被提交。



在存储库中使用 git stash 时,这些更改将与其他任何未完成的更改一起保留。这是预期的行为,但是 git stash pop 不会让它们回来,所以更改只会丢失。



任何人都知道如何阻止假定文件不变位的文件被隐藏起来?或者,您可能知道如何确保对这些文件进行的任何更改至少会被带回来?

不变就是性能破坏,并代表你承诺文件没有改变。如果你真的改变了文件,所有的投注都关闭。你应该重新构建你的repo,这样你就不会提交这些文件(可能会提交filename.sample和.gitignore文件名)或者使用分支来玩技巧,这样你不想与其他人分享的文件就不会与其他人分享了分支或以其他方式隐藏。



我已经看到/想到了有关如何隐藏这些更改的四条建议。



1:使用涂抹/清洁过滤器将文件更改为结帐时需要的内容,并在签入时将其清理干净。丑陋。



2:按照 http://thomasrast.ch/git/local-config.html 这里要记住的关键是您在主分支上开发并合并到配置分支进行测试。返回到主分支进行更改,推送等。



3:创建一个私人开发分支,进行不想共享的更改,然后进行假合并(混帐 - 我们的privatebranch)。然后,您可以在您的私人分支上开发和测试,并且只要变更远离您的正常工作,您不希望共享的变更就不应该归于合并分支。但是,当您从上游获得新的更改时,您需要将它们从上游直接拖入私有分支。然后,您从私有的后端合并到主服务器并从主服务器向上推。你绝对不能从主人合并回私人。同样,你也绝对不可以变硬(好吧,可能rebase -p会起作用,但不能保证)。这些合并/重新分配以及每个必须发生的地方使得它们不那么有吸引力。



4:创建一个私有开发分支,进行你不想共享的更改,然后创建一个合并驱动程序(请参阅man gitattributes),它会拒绝将有问题的文件从主文件合并到私有文件或从私有文件合并到主文件(可能通过将私有分支上文件的SHA与各分支的SHA进行比较并复制以前的值)。


I have used git update-index --assume-unchanged on some files to keep my changes to them from being committed.

When using git stash in the repository, those changes are stashed along with any other outstanding changes. This is expected behaviour, however git stash pop doesn't bring them back, so the changes are just lost.

Anyone know how to either prevent the files with the assume unchanged bit from having their changes stashed? Alternatively perhaps you know how to make sure that any changes that are stashed against those files are at least brought back?

解决方案

assume-unchanged is a performance hack, and represents a promise from you that the file has not changed. If you actually change the file all bets are off. You should either rearchitect your repo so that you don't commit these files (perhaps commit filename.sample and .gitignore filename) or play tricks with branches so that the files you do not want shared with the rest of the world are off on another branch or otherwise hidden.

I have seen/thought of four suggestions on how to hide these changes.

1: Use a smudge/clean filter to change the file to what you want on checkout and clean it on checkin. Ugly.

2: Create a local configuration branch as described in http://thomasrast.ch/git/local-config.html The critical thing to remember here is that you develop on the primary branch and merge onto the config branch for testing. Back out to the primary branch to change, push, etc.

3: Create a private development branch, make the change you never want shared, and then make a fake merge (git merge -s ours privatebranch). You can then develop and test on your private branch and the change you do not want shared should not be when you merge back, as long as the change is far away from your normal work. However, when you get new changes from upstream, you need to pull them directly from upstream into the private branch. You then merge from private back into master and push upstream from master. You must never merge from master back into private. Likewise, you must never rebase (well, possibly rebase -p would work, but no guarantees). These merge/rebase and where each must occur makes this less attractive.

4: Create a private development branch, make the change you never want shared, and then create a merge driver (see man gitattributes) which will refuse to merge the file in question from master to private or from private to master (probably by comparing the SHA of the file on the private branch to the various branch's SHAs and copying the previous value if it matches).

这篇关于如何防止使用“假定不变”的git存储丢失更改位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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