2

I have a git repository that's public on github.

There, I have a local file I don't want to share to the public, while other team members want it to be public, so I did git update-index --assume-unchanged (that file).

Now, I want to switch to a different branch. It tells me that there are changes on that file I have to commit or reset. When I try to commit, it says that there are no changes to commit. When I reset (with git reset --hard), it doesn't do anything.

What can I do?

milkwood1
  • 237

2 Answers2

1

Instead You can stash your change and make changes later as you wish like change branches etc once when you need that stashed changes back you can unstash your change back

check the link Stash the change perfectly expliang how to stash and unstash changes

DEV
  • 11
0

I ran into the same thing today, and I found a solution that worked from this page (couldn't figure out who the author was so that I could give credit):

The solution that worked for me was to use --skip-worktree. However, like some above, I struggled with being able to switch between a ticketed branch and the main branch without git complaining even after I had set the --skip-worktree flag on the file whose changes I wanted to remain local.

...

  1. cp <local-only_file> ~/
    • copy file that has your local-only changes to somewhere safe on the filesystem
  2. git checkout <local-only_file>
    • in working tree, checkout file so that it matches master branch file
  3. git update-index --skip-worktree -- <local-only_file>
  4. cp ~/<local-only_file> ./
    • copy file in question from safe location back into working tree
  5. git diff
    • no changes should be shown; if you push to the main repo, no changes in <local-only_file> are included in the push

The full solution began with git update-index --no-assume-unchanged <filename> before proceeding with the steps above. After following these steps, I was able to switch branches.