Not Possible to switch branch after --skip-worktree

后端 未结 7 1218
醉酒成梦
醉酒成梦 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:20

    Well, this is a cruddy solution, but seems to work reasonably well (though it is only lightly tested):

    Create a file named git-checkoutsw somewhere in your PATH, with the following content:

    #!/bin/bash
    ignored=( $(git ls-files -v | grep "^S " | cut -c3-) )
    for x in "${ignored[@]}"; do
      git update-index --no-skip-worktree -- "$x"
    done
    git checkout -m $@
    for x in "${ignored[@]}"; do
      git update-index --skip-worktree -- "$x"
    done
    

    The script captures the list of ignored files, unignores them, checks out the new branch with -m (for merge) and whatever other parameters have been specified, and then ignores them again.

    Now you can do git checkoutsw instead of git checkout.

提交回复
热议问题