Add all files to a commit except a single file?

前端 未结 13 872
遇见更好的自我
遇见更好的自我 2020-11-28 17:03

I have a bunch of files in a changeset, but I want to specifically ignore a single modified file. Looks like this after git status:

# modified:          


        
13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 17:39

    Now git supports exclude certain paths and files by pathspec magic :(exclude) and its short form :!. So you can easily achieve it as the following command.

    git add --all -- :!main/dontcheckmein.txt
    git add -- . :!main/dontcheckmein.txt
    

    Actually you can specify more:

    git add --all -- :!path/to/file1 :!path/to/file2 :!path/to/folder1/*
    git add -- . :!path/to/file1 :!path/to/file2 :!path/to/folder1/*
    

    For Mac and Linux, surround each file/folder path with quotes

    git add --all -- ':!path/to/file1' ':!path/to/file2' ':!path/to/folder1/*'
    

提交回复
热议问题