0

I have commited two files, let us say a.json and b.json. I have these files locally and on the remote repository.

I want to basically make some changes to b.json but just ignore pushing it the the remote repository, but accidentally commited them.

I have tried git rm --cached b.json and then amended the commit. But pushing this removes b.json from my remote repository.

I would want the b.json on the remote to remain the same just would want to not push my changes. How would I achieve this?

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
sak18
  • 101
  • 13
  • Are the changes of a sensitive nature? If not, I would just use `git revert` to create a new commit that undoes the change, then push *that* commits to the remote as well. – chepner Sep 20 '21 at 14:27
  • Is your question about reverting `b.json` https://stackoverflow.com/questions/2620775, remove all traces of your mistake https://stackoverflow.com/questions/48975429 or avoiding to commit local changes https://stackoverflow.com/questions/7239333 anymore ? – Orace Sep 20 '21 at 14:28
  • Does this answer your question? [How do I commit only some files?](https://stackoverflow.com/questions/7239333/how-do-i-commit-only-some-files) – Orace Sep 20 '21 at 14:29

1 Answers1

0

First, copy the file to somewhere else entirely.

Now checkout the file from a commit where the file was "good". Add the file, commit, and push. Now the remote version of the file is correct.

Now copy the file back from where you saved it and go on with your work.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • `First, copy the file to somewhere else entirely.` sounds like `First don't use git at all`. – Orace Sep 20 '21 at 14:30
  • @Orace Not at all. Just don't commit files that you don't want to push — then you don't need to remove them. – phd Sep 20 '21 at 14:46
  • @phd, don't `stage` the files you don't want to commit. Use stash instead of `move somewhere else`. – Orace Sep 20 '21 at 14:51
  • 1
    @Orace I absolutely considered telling the OP to stash, and rejected that idea. I'm not fond of stashing and I don't want to recommend it, especially to a beginner. — Also, _lots_ of Git commands deserve saving off a copy as a safety. It's no shame. – matt Sep 20 '21 at 15:05