How to NOT commit locally deleted files to git

后端 未结 4 1446
醉梦人生
醉梦人生 2021-01-22 18:33

We have a situation where were are using git to stash myriad scans (images) and do not wish to preserve them on the local machine once set on up; however, git is seeing each loc

4条回答
  •  梦毁少年i
    2021-01-22 19:20

    Use the Skip-Worktree Bit

    The git-update-index(1) command provides some ways of dealing with this. Based on the assumption that you want to keep the blobs in your history while deleting them from your working tree, you could use the following:

    git add --all
    git commit --message="Add new assets to repository."
    git update-index update-index --skip-worktree 
    rm 
    

    Note that the last line isn't a Git command because you're removing the files from the working tree in the shell after you've stored them in the index. Don't use git rm by mistake, because it operates on the index.

    Listing Your Special Bits and Index-Only Files

    To see the files you've marked with the skip-worktree bit:

    git ls-files -v | awk -v IGNORECASE=1 '$1 ~ /s/ {print}'
    

    You can also use git-ls-files(1) to find files in the index that have been removed from your working tree.

提交回复
热议问题