0

I have a GitHub repo where I keep mainly .tex files, with Makefiles that compile all of the files to create .pdfs. On this repo, the .gitignore file serves to ignore some compilation files related to this, most notably the .pdfs themselves. Now I also have some files that aren't the result of compiling the .tex files, and should therefore not be ignored by git. I recently added some code (using the minted package) in my .tex files that creates compilation files of two certain types, namely .pygstyle and .pygtex. These files are files I don't want to keep in the repo, hence I added them to my .gitignore--after already adding them in a previous commit :(.

I'd like to find the commands I'd have to type in order to rebase this branch in a way that doesn't remove all files in the .gitignore from source control, seen as there are some .pdfs that I'd like to keep, but the compilation files I mentioned above should be ignored.

I tried rebasing the normal way, only to find out about those lost files that couldn't be ignored; ever since, I've been aimlessly rebasing onto new branches, with little to no success.

Ideally, there would be a way to retroactively apply the .gitignore file to the commits introducing the "naughty files", without removing other files that were manually added to bypass the .gitignore.

I thought about not using rebase (for example by simply applying the .gitignore to a subset of all the files), but I'd like to keep it clean and use git rebase instead.

Peiffap
  • 153
  • 1
  • 12
  • Possible duplicate of [How to filter history based on gitignore?](https://stackoverflow.com/questions/43463687/how-to-filter-history-based-on-gitignore) – phd Jan 26 '19 at 03:27

1 Answers1

1

If your naughty files are small, I would suggest simply git rming them and committing the results. From that point on, .gitignore will work as you want, since the files will no longer exist in the commits you'll be working on.

If your naughty files are large, you can use git filter-branch to rewrite the history without those files. This question will help if you chose this route: How to remove/delete a large file from commit history in Git repository?

For a bit of additional information, the .gitignore file only affects what happens in a git add and in operations that compare the current state of your sandbox with the current commit. When you rebase, you're asking Git to reapply a given commit with the files and patches it has, as is (by default). You have to edit the commit to remove a file out of it, and the question linked in the previous paragraph explains how to do that manually or via git filter-branch.

joanis
  • 4,360
  • 4
  • 21
  • 30