With git, temporary exclude a changed tracked file from commit in command line

I have a tracked database (already added) file in git. I want this file to always contain the same data in my git repository. Even when I modify it in the working copy (local sandbox) for test purposes.

With git, how to exclude this changed file on my working copy from a commit ?

  • Cannot push to git from windows/phpstorm
  • How do I make a Scala project “Import from git”able in Eclipse?
  • Does Accurev support stashing?
  • How can two branches become “linked” in git?
  • Which commit has this blob?
  • why does bare repository have HEAD
  • Using the same deploy key for multiple github projects
  • What is a blob under the hood?
  • Git subprojects?
  • git diff --cached: refname 'HEAD' is ambiguous
  • git clone in .bat script
  • Resolving same conflicts again and again when doing rebasing more times
  • 6 Solutions collect form web for “With git, temporary exclude a changed tracked file from commit in command line”

    The way to ignore certain files that are already committed is

    git update-index --assume-unchanged file

    However, this is a local setting, and it doesn’t propagate when cloning.

    Its effect is canceled with git update-index --no-assume-unchanged gui.

    Additionally to using git add I would suggest to use a shell with more capabilities, i.e. zsh. Here you can insert extended globbing like *~*.o(.) which means all files except such ending with o. This make it easier to add all files except one. Zsh also allows you to set a global alias: alias -g AF="*~*.o(.)". So you can type git add AF and it will be expanded in the right way.

    If you don’t do git commit -a, git commit will only commit files that you have explicitly added to the index using git add.

    simply do not add it with git add, but add any other file you want to commit

    then use git commit instead of git commit -a

    The smarter way to do this is to not track the database at all, directly. Track an example database and then each developer can copy it and modify it, and it can be under gitignore.

    1. add this file to your repo
    2. commit
    3. add it to .gitignore file
    4. commit .gitignore file
    Git Baby is a git and github fan, let's start git clone.