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:
web.config
, createDb.sql
or in any othersThe 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:
git -add -A -EXCEPT web.config crateDb.sql
. Then I can map a git alias to that and that's it.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.
Here is how to save local changes without commit in Git. Just issue git stash command as shown below from your present working directory which contains unsaved unchanges. This will stash all changes you made and your repository will be restored to your last commit.
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.
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