0

I am working in a shared git repository. In our project, we have a configuration.json file that holds information to some parameters for the project. Sometimes when I am working on my local repository, I change the contents of configuration.json to test things out, but always end up discarding my changes because I don't want to commit my 'tested' changes.

If I don't track configuration.json, then committing would cause the whole file to disappear from the repository on github, since the github repository originally has the file, and by committing my local version of the repository (which does not have the configuration.json tracked) would cause me to commit my local version of the repository which does not have configuration.json anymore.

Usually how I work around this is by discarding my changes manually, which is not the best solution because sometimes I want to commit my other changes within the project, while keeping my changes of configuration.json in my local device, without actually committing it to the shared repository on github.

Is there a way to be able to not track my changes to a file, while not causing it to disappear when i make commits to the github repository?

Ken
  • 49
  • 5
  • Are you aware that you can select the changes from which a commit is created? It is typically called "to stage the change". (Some also call it "index" or "cache" in the context of Git.) When you stage your changes for the next commit carefully, you do not have to discard your changes to that JSON file. – j6t Apr 19 '23 at 10:31
  • If I stage it, I would have to commit and push it otherwise there would be "uncommitted staged changes" no? But the problem now is that I don't want to push my changes to that JSON, and yet I don't want it to disappear from the repository when I don't track it. – Ken Apr 19 '23 at 10:41
  • https://stackoverflow.com/search?q=%5Bgit%5D+track+config+ignore+changes – phd Apr 19 '23 at 10:42
  • What I'm saying is that you shoud *not* stage your change. Then it is not in the commit you are about to make. – j6t Apr 19 '23 at 10:42
  • `git update-index --skip-worktree configuration.json` – phd Apr 19 '23 at 10:42
  • “Some also call it "index" or "cache"—“cache” is (Git 2.40.0) an obsolete term (`man gitglossary`). “index” is preferred instead. – Guildenstern Apr 19 '23 at 11:00
  • This might not be a duplicate of the linked questions if OP wants to simply commit the changes somewhere _else_ (like a separate branch). But unless they do some follow-up comments or edits we can’t know. – Guildenstern Apr 19 '23 at 16:02

1 Answers1

0

Sometimes when I am working on my local repository, I change the contents of configuration.json to test things out, but always end up discarding my changes because I don't want to commit my 'tested' changes.

Make a branch in your own (your local) repository named my-temporary-change or something.

Commit that change with a commit message that clearly states that it’s a temporary change (maybe start the commit message with “TEMP” or something).

Then cherry-pick that commit into whatever you’re working on temporarily; when you’re done you can drop/delete the commit with git-rebase(1) or something else that rewrites history.

If you don’t need this branch with your temporary commit to be shared on the GitHub remote then you can just keep it in your own local repository. You don’t have to push it to the GitHub remote.

Guildenstern
  • 2,179
  • 1
  • 17
  • 39