0

I have made couple of commits to my branch and pushed it to the remote. I didnt notice some unwanted files were added/modified and they were commited as well in one of the first commits. Is it possible to remove only those changes? (only the unwanted files)

Thank you!

123456
  • 113
  • 8
  • 1
    Possible duplicate of [Completely remove file from all Git repository commit history](https://stackoverflow.com/questions/307828/completely-remove-file-from-all-git-repository-commit-history) – phd Nov 04 '17 at 19:00

1 Answers1

0

Git doesn't exactly store files. Instead, Git stores commits (and then the commits have files).

Git is very much oriented towards adding new commits. You can add new commits in which the files are not present. This means that whenever you check out the old commit, the file is present—it gets added to your work-tree—and then whenever you switch to the new commit, the file gets removed. (Would you say that this file is, or is not, in the repository? Why, or why not?)

If that's sufficient, simply remove the unwanted file(s) with git rm, commit the result, and push the new commits to add them to the upstream version of the repository. The newest commit now does not have the file(s). Since checking out a branch checks out the newest commit that is the tip of that branch, git checkout <whatever-branch> will give you a work-tree that does not have the file(s). But the files are still in the older commits.

If that's not sufficient, see the linked possible-duplicate.

torek
  • 448,244
  • 59
  • 642
  • 775