Not Possible to switch branch after --skip-worktree

后端 未结 7 1219
醉酒成梦
醉酒成梦 2020-12-13 03:37

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 achiev

7条回答
  •  执念已碎
    2020-12-13 04:25

    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.

    Update: I've run into this problem again so have created a PowerShell script instead of the .bat file mentioned above. It will prompt the user whether they want to skip or no-skip the files. Update the two parameters and you're ready to go:

    [string]$repoPath = "C:\Fully\Qualified\Path"
    [string[]]$filesToSkip = @(
        "Local/Path/To/File.txt",
        "Local/Path/To/OtherFile.txt"
    )
    
    $skipText = Read-Host -Prompt 'Skip files? (y/n)'
    $skip = $skipText -like "y"
    cd $repoPath
    foreach ($file in $filesToSkip)
    {
        if($skip)
        {
            Write-Host "Skipping" $file
            git update-index --skip-worktree $file
        }
        else
        {
            Write-Host "No-skipping" $file
            git update-index --no-skip-worktree $file
        }
    }
    

提交回复
热议问题