1

I am working with a bunch of files but would not like to commit some of them.

Rather than commit each file individually is there a way I can exclude the files I do not want to commit?

From reading similar questions on SO, I've tried various instances of git stash but have not been able to get them to work, eg:

git stash file.ext
git stash -- file.ext
git stash push "file.ext"
git stash push -- file.ext

Would anyone know how I could do this?

MeltingDog
  • 14,310
  • 43
  • 165
  • 295

2 Answers2

0

You can put the filenames/ directories/ extensions in a .gitignore file in your repository directory.

Ex:

# ignore files with extention .ext
*.ext
# ignore directory
some_dir/
# ignore files in a directory but keep particular ones
some_other_dir/*
!some_other_dir/*.tar.gz

However if you have already done a commit with files that you don't want to be in the git repo, take a look at this answer

Teshan Shanuka J
  • 1,448
  • 2
  • 17
  • 31
0

If those files:

  • are already versioned, and you need to keep them in the repository (meaning they are not private files to be ignored)
  • can be changed locally, but should not be added/commited

You can try, from "Difference Between 'assume-unchanged' and 'skip-worktree'"

git update-index --skip-worktree -- a file
git update-index --no-skip-worktree -- a file
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250