10

What I want to do is already described in that question. But I want to solve that problem in a practical and more generic way. So the use-case is the following:

  • I have several local changes in several files web.config, createDb.sql or in any others
  • I don't want to commit those files, since changes are specific to my local machine only
  • Those files must be version controlled and moreover changes are made pretty often to some of them (sql scripts in particular), so I want to receive updates for those files
  • I do want to commit all other files
  • I want to be able to do that without friction, in one command (using posh-git, so powershell is welcome)

The linked-to solution said to use git add -p and that is not practical, it is boring to pick chunks manually all the time or maybe there is a more convenient way of doing that?

For instance, one of the following could work:

  • if there is an ability to filter files that are in my working copy before adding them to index, something like git -add -A -EXCEPT web.config crateDb.sql. Then I can map a git alias to that and that's it.
  • if there is an ability to de-apply stash. I mean to remove changes that is contained in one specific stash from the working copy. So I will have to do something like git stash -deapply before each commit that is also fine.

The problem is very common and it is weird that there is no solution currently. E.g. TortoiseSVN has "ignore-on-commit" feature, Perforce allows to store that type of local changes in a separate changelist and never submit it.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Restuta
  • 5,855
  • 33
  • 44
  • How else can you "version control" those files besides committing the changes? In git, committing _is_ local, and _push_ affects other computers/repos. To me, this smells like a better solution is something like [this](http://stackoverflow.com/questions/6009/how-do-you-deal-with-configuration-files-in-source-control). – Alexander Bird Apr 19 '12 at 21:08
  • I have a better solution for config files - [NConifig](https://github.com/Yegoroff/NConfig), but the problem is that I have not only configuration files. – Restuta Apr 19 '12 at 21:14

1 Answers1

10

You could try doing the following before your git commit:

git update-index --assume-unchanged web.config crateDb.sql

From git help:

--assume-unchanged

--no-assume-unchanged

When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

Community
  • 1
  • 1
BluesRockAddict
  • 15,525
  • 3
  • 37
  • 35
  • How git will behave after that? Will it still track those files? If I will get an update that will happen? – Restuta Apr 19 '12 at 20:40
  • 1
    @Restuta The files will still be tracked by git, but git will temporarily regard them as not changed, even if they have changed. So git status etc will not report the files being changed. Use --no-assume-unchanged to undo the command and let git care about changes again. – rtn Apr 19 '12 at 20:54
  • Are you sure that while being in the state --assume-untracked it will get updated? Or you mean that I have to "untrack -> commit -> track" it? – Restuta Apr 19 '12 at 23:38