I have seen many related discussions, but not an exact resolution to my particular problem. I want to remove one step in the history for a specific file.
So for example, I add a file "Foo.txt". I commit my changes. Then I modify a bunch of files. I commit again. Now, I want to revert "Foo.txt" to an earlier commit, and also delete the history of the changes.
I know that the command
git checkout "aasdfasdfad" Foo.txt
will revert the state of Foo.txt to whatever it was on commit "aasdfasdfad". However, git still has the previous version of "Foo.txt" in its state, somehow. How do I know that? Because in my case, the size of "Foo.txt" changed from a few bytes to a megabyte. So when I revert to the earlier version, the size of my .git directory should go down by about a megabyte, but it doesn't change.
Somehow, I have to tell git that I not only want to revert to an earlier version of Foo.txt, but that I want to throw away all changes to Foo.txt since then.
[added later] Just to make it absolutely clear what I'm trying to do, let me show a very specific scenario:
- [create file foo.txt. Now, it is 1KB in size.]
- git add foo.txt
- [create file bar.txt]
- git add bar.txt
- git commit -m "small file"
- [modify foo.txt. Now it is 1GB in size.]
- git add foo.txt
- [modify bar.txt]
- git add bar.txt
- git commit -m "huge file"
At this point, I want to reset foo.txt to the state that it was in after step 3. But I want bar.txt to have the state that it was in after step 8. So I want the files and the history to look as if I had never done steps 6 and 7