1

I have some files that are excluded from git changes.
I can changes the file locally, and the changes is not shown in the git status.

But, if I try to squash the branch or, try to checkout to new branch, it doesn't allow me to do so, without committing the changes to those file.

How can I manage those files?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
priosshrsth
  • 1,070
  • 2
  • 11
  • 30

2 Answers2

0

or, try to checkout to new branch, it doesn't allow me to do so, without committing the changes to those file.

That is why Git 2.25.1 (Feb. 2020) now includes in git update-index:

Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked.

This does not work as expected, since Git may still check working tree files against the index when performing certain operations.
In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended.

For example, if the file you want to change is some sort of config file, the repository can include a sample config file that can then be copied into the ignored name and modified.
The repository can even include a script to treat the sample file as a template, modifying and copying it automatically.

I reference the last part in a content filter driver based on smudge/clean scripts.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • having sample file and copying it is not an option for me me unfortunately, since, the file needs to be changed and pushed by other members. – priosshrsth Mar 19 '20 at 06:21
  • @priosshrsth The content filter driver means you have a private file generate, while an official file (with different name) can still be changed and pushed. – VonC Mar 19 '20 at 06:23
0

I'm assuming that those files are some configuration files. I'd suggest the following approach. Let Git know about the changes:

git update-index --no-skip-worktree EACH_FILE 

Stash those changes:

git stash save "Save local conf"

You can now checkout to the other branch without problems, then restore your local changes:

git stash pop

and you can fix the conflicts, if any, accepting your local changes.

saccodd
  • 972
  • 9
  • 23