在--skip-worktree之后不能切换分支 [英] Not Possible to switch branch after --skip-worktree

查看:340
本文介绍了在--skip-worktree之后不能切换分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么



我有一个包含敏感数据的文件,因此我不想将此文件的内容推送到远程服务器。

我做了什么?



为了达到这个目的,我在文件为空时提交了一个提交,空文件到服务器(GitHub)。然后用敏感数据填充文件并应用 git update-index --skip-worktree path / to / file 。但我没有做任何承诺。



现在我试图切换我的分支,但是我收到这个错误:

 错误:对以下文件的本地更改将被checkout覆盖:
path / to / file
请在您切换分支之前提交更改或存储它们。
中止



为什么我要使用 skip-worktree INSTEAD OF 假定 - 不变



我读了几个关于这个主题的SO问题, a href =https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree/13631525#13631525> Borealid的答案。


- 承担 - 不变假定开发人员不应更改文件。这个标志是为了提高不变文件夹(比如SDK)的性能。



- 当您指示git不触摸特定文件时,skip-worktree会很有用,因为开发者应该改变它。例如,如果主库上游托管了一些生产就绪的配置文件,并且您不想意外地对这些文件提交更改,--skip-worktree正是您想要的。


blockquote>

在此之后,我发现 Jeff的问题 VonC的回答。 Jeff的问题与我的问题几乎相同,我遵循VonC的解决方案。然而这对我来说并不合适。也许是因为git版本的差异。因为这个问题从2012年开始。我们和VonC谈过了,他说这是一个新问题,因为他不记得答案。



我试着用 - 承担 - 不变 - skip-worktree 在一起,以及软重置工作树。但没有任何改变。



SO?



你能帮我解决我的问题吗?



谢谢。

解决方案

我一直无法找到一个简洁的解决方案,因此我使用 .bat 文件在受影响的文件上运行 - no-skip-worktree 。然后我使用 stash ,开关分支, stash apply ,然后使用另一个 .bat 文件在同一文件上运行 - skip-worktree



这不好,但这是迄今为止我找到的最简单,最快捷的方式。


WHAT I WANT TO DO

I have a file which contains sensitive datas so I don't want to push content of this file to remote server.

WHAT I DID?

To achieve this, I made a commit when the file was empty and pushed this empty file to server (GitHub). And then fill the file with sensitive datas and applied git update-index --skip-worktree path/to/file . But I didn't made any commit.

Now I'm trying to switch my branch but I'm getting this error :

    error: Your local changes to the following files would be overwritten by checkout:
    path/to/file
    Please, commit your changes or stash them before you can switch branches.
    Aborting

WHY I USE skip-worktree INSTEAD OF assume-unchanged?

I read a few SO questions about this subject, and found Borealid's answer.

--assume-unchanged assumes that a developer shouldn’t change a file. This flag is meant for improving performance for not-changing folders like SDKs.

--skip-worktree is useful when you instruct git not to touch a specific file ever because developers should change it. For example, if the main repository upstream hosts some production-ready configuration files and you don’t want to accidentally commit changes to those files, --skip-worktree is exactly what you want.

After this, I found Jeff's question and VonC's answer. Jeff's problem is almost same with mine, and I followed VonC's solution. However it's not work for me. Maybe because of git version difference. Because that question from 2012. We talked with VonC and he said to ask this as a new question because he couldn't remember answer.

I tried to use --assume-unchanged and --skip-worktree together, and soft reseting worktree. But nothing changed.

SO?

Can you help me about my problem ?

Thank you.

解决方案

I haven't been able to find a neat solution to this, so I'm using a .bat file to run --no-skip-worktree on the affected files. I then stash, switch branch, stash apply, and then use another .bat file to run --skip-worktree on the same files.

It's not nice, but it's the simplest and quickest way I've found so far.

这篇关于在--skip-worktree之后不能切换分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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