如何保存git reset --hard存在的一些本地更改 [英] How I can store some local changes that survives git reset --hard

查看:198
本文介绍了如何保存git reset --hard存在的一些本地更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我不想提交的本地更改(不在单独的文件中,所以.gitignore不起作用)

git reset --hard 有时在承诺清除偶然更改但有意义之后,我也失去了我想离开的有用更改。



我可以保留我的有用更改吗?

解决方案

您还可以尝试:

  git update-index --skip-worktree  - 文件
#取消它:
git update-index --no-skip-worktree - file

它应该抵抗 git reset --hard 。 (请参阅此答案关于' - '双连字符的使用)

查看此博客文章



  • 它看起来像 skip-worktree 非常难以保存您的本地数据。但是,如果它是安全的,它并不妨碍你获得上游的改变。加上git不会重置拉标志。但是忽略'reset - hard'命令对于开发人员来说可能会是一个令人讨厌的惊喜。
  • 假定 - 不变标志可能会丢失对于pull操作以及这些文件中的局部变化似乎对git来说并不重要。

    假设 - 不变假定开发人员不应该更改文件。如果一个文件被改变 - 比这个改变并不重要。此标志旨在提高不变文件夹(如SDK)的性能。但如果诺言被破坏并且文件实际上发生了变化,那么git会回复标志以反映现实。可能在通常不需要更改的文件夹中有一些不一致的标志是可以的。


    另一方面,当您指示git时, skip-worktree 很有用不要触摸特定的文件。这对于已经跟踪的配置文件很有用。上游主存储库承载一些生产就绪配置,但您想要更改配置中的某些设置以便能够进行一些本地测试。并且您不希望意外检查此文件中的更改以影响生产配置。在这种情况下, skip-worktree 制作完美的场景。


I have some local changes (not in separate files so .gitignore doesn't work) that I don't want to commit.
I do git reset --hard sometimes after commit to clear occasional changes but obiously I also lose my useful changes that I want to leave.

How I can keep my useful changes?

解决方案

You can also try:

git update-index --skip-worktree -- file
# to cancel it:
git update-index --no-skip-worktree -- file

It should resist a git reset --hard. (see this answer on the '--' double hyphen use)
See this blog post.

  • It looks like skip-worktree is trying very hard to preserve your local data. But it doesn’t prevent you to get upstream changes if it is safe. Plus git doesn’t reset the flag on pull. But ignoring the ‘reset --hard' command could become a nasty surprise for a developer.
  • assume-unchanged flag could be lost on the pull operation and the local changes inside such files doesn’t seem to be important to git.
    Assume-unchanged assumes that a developer shouldn’t change a file. If a file was changed – than that change is not important. This flag is meant for improving performance for not-changing folders like SDKs. But if the promise is broken and a file is actually changed, git reverts the flag to reflect the reality. Probably it’s ok to have some inconsistent flags in generally not-meant-to-be-changed folders.

On the other hand, skip-worktree is useful when you instruct git not to touch a specific file ever. That is useful for an already tracked config file. Upstream main repository hosts some production-ready config but you would like to change some settings in the config to be able to do some local testing. And you don’t want to accidentally check the changes in such file to affect the production config. In that case skip-worktree makes perfect scene.

这篇关于如何保存git reset --hard存在的一些本地更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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