-3

I have a bunch of C header files that use a generic #ifndef XXXXXX naming structure. I'd like to modify all of those header file to #ifndef YYYYYYY, and save the changes in the git repo without having to commit. Is it possible to change a file (or multiple files) and ripple those changes in all previous commits? Or is it possible to change a bunch of files and save the changes in the repo without commiting at all?

Maslin
  • 139
  • 6
  • Nope, the point of git is you won't get unknown changes without actual commits. – Martheen Jul 21 '22 at 21:14
  • I understood it as OP wanted to rewrite all history for a file, not just adding a commit on top. Is it so, @Maslin? (I was about to close the question as a duplicate of [this one](https://stackoverflow.com/questions/4110652/how-to-substitute-text-from-files-in-git-history)) – Romain Valeri Jul 21 '22 at 21:16
  • 1
    "save the changes in the git repo without having to commit" The repo consists _entirely_ of commits. What gets saved _is_ a commit. Always. "Is it possible to change a file (or multiple files) and ripple those changes in all previous commits?" Commits are immutable. So, yes, except that you would be replacing those previous commits with new commits. – matt Jul 21 '22 at 21:16
  • But we don't know yet if rewriting all history is a problem in OP's context. Let's wait for their input :-) – Romain Valeri Jul 21 '22 at 21:21

1 Answers1

0

Is it possible to change a file (or multiple files) and ripple those changes in all previous commits?

Technically, yes. You can use git filter-branch to make those changes across all commits. But I do not recommend doing this in a repo that has been pushed to a place accessible by others: this operation will modify every single commit which will cause problems with anyone else who has to pull down the changes. My recommendation would be to change all of the header files and commit those changes in a single commit.

Or is it possible to change a bunch of files and save the changes in the repo without commiting at all?

Well, yes, I guess so, but the changes won't be reflected in the repository, so no one else will be able to see those changes, and they will forever be marked as modified, which is probably not what you want to do.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • 2
    Technically no. Filter-branch doesn't modify any commits. It _replaces_ commits. – matt Jul 21 '22 at 21:19
  • 1
    Also `filter-branch` is pretty much a dead letter; you should be advising the use of `filter-repo` if you're going to go that route. – matt Jul 21 '22 at 21:21
  • 2
    filter-branch has its strengths, filter-repo has its weaknesses. [There's stuff I have no idea how to make filter-repo do](https://stackoverflow.com/questions/67961146/use-git-filter-repo-to-filter-out-a-list-of-files-in-commits-which-are-not-desce). – jthill Jul 21 '22 at 21:36