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
  • 227
  • 1
  • 3
  • 7
  • The [Git documentation](https://git-scm.com/docs/git-update-index#_notes) states that `git update-index --assume-unchanged` should not be used for this. – bk2204 Mar 16 '20 at 00:37
  • what instead, why and what should I do now? I even tried undoing it with --no-assume-unchanged but doesn't work – milkwood1 Mar 18 '20 at 13:38
  • Can you edit your question to include the output of `git diff` and `git status`? – bk2204 Mar 18 '20 at 20:39
  • 1
    @bk2204 That's the problem, with git diff it doesn't show anything and git status says that there's nothing to commit – milkwood1 Mar 20 '20 at 12:32

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
  • 2
  • 1
    Didn't help. It still says that this specific file has changes when I try to switch branches but otherwise says there are no changes – milkwood1 Mar 13 '20 at 16:52
  • @Darxoon, ask for the changes! `git diff` works wonders... – vonbrand Mar 13 '20 at 17:37
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Mokubai Mar 13 '20 at 23:07
  • 1
    @vonbrand doesn't do anything – milkwood1 Mar 14 '20 at 15:46
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.