I want to commit all files except for one file. Can I do that using the GitHub for Windows client or do I need to use the command line? If I need to use the command line, how do I use it?
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
So you can easily achieve it as the following command. The -- option separates the add command from the list of files, so the files won't be mistaken as command-line options. In the case above, all files in the current directory (.), except excludedfile .
Use your favorite text editor to open the file called . git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.
As far as I know this is not possible without using the git shell/command line. In the Git Shell you have several options. All of them yield a slightly different result.
If you only want to exclude the file for a little time (maybe one commit) and add it in a future commit you can execute the following commands:
git add . git reset filename git commit -m "commit message"
The first command adds all files to the staging area. Then the second command removes the one file from the staging area. This means the file is not added in the commit but the changes to it are preserved on your local drive.
If the file is already committed to the repository but you only sporadically want to commit further changes of the file, you can use git update-index --assume-unchanged
in this way:
`git update-index --assume-unchanged filename`
If you then change the file locally it will not get added to the staging area when you execute something to add all files, like git add .
. When, after some time, you want to commit changes to the file again, you can run git update-index --no-assume-unchanged filename
to stop ignoring the changes.
You can use the .gitignore
file if you don't want to track a file at all. To ignore a file named filename
you create, or edit, a file called .gitignore
. Put filename
on a line of its own to ignore that file. Now the file is not added to the staging area when you execute git add .
. Remark: If the file is already checked in you have to remove it from the repository to actually start ignoring it. Execute the following to do just that:
`git rm --cached filename`
The --cached
option specifies that the file should only be removed from the index. The local file, whether changed or not, will stay the same. You can add the .gitignore
file and commit to make the file get ignored at other machines, with the same repository, as well.
If you want to ignore an untracked file but don't want to share this ignoring with other repository contributors you can put the names of ignored files into the file .git/info/exclude
. The .git
directory is normally hidden but you can make it visible by altering the folder options. As with the .gitignore
file, you have to execute git rm --cached filename
if the file was already checked in by a previous commit.
Some notes:
filename
into the actual name of the file you want to exclude.filename
.Open in Git Shell
. Now you are at the root of the git repository and you can start executing the commands that are shown and described in this answer.You can just create a .gitignore file and add the name of the file you want to exclude in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With