Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm happy enough with git most of the time. But the porcelain still sucks for a few things that feel like the should be basic and it doesn't feel like it's getting better or that any new tools have been written that fix the gaps for me.

One problem I've had recently is that I've wanted to store a large JSON file on GitHub (that's, importantly, modified slightly each commit), but with indentation it's over 100mb so GitHub doesn't allow it. I can strip out the indentation and that takes it down to 60mb or so, but the large objects are still in git history so they get rejected, so evidently I need to rewrite the git history.

Unfortunately, if you just take an old commit, strip the indentation from the JSON and try to rebase all the other commits on top of that, it'll fail as git treats each commit as a patch and the patches to the unindented JSON don't make sense. What I really want is to for git to treat each commit as a repository state, so that removing indentation from the state at commit A means that the patch for commit B adds all the indentation, and then I can just write a loop that rewrites each commit state. This seems like something that there should be better tooling for, I mean `git filter-branch` exists but I don't think it works for this usecase.

Edit:

Here’s what chatgpt suggests (for rust code):

```python

    import os
    import subprocess

    def reformat_file(repo, commit, file_name):
        # Check if the file exists in this commit
        if os.path.isfile(file_name):
            # Run cargo fmt to format the file
            subprocess.run(["cargo", "fmt"], check=True)
            # Stage the changes
            subprocess.run(["git", "add", file_name], check=True)

    def main(repo):
        file_to_fix = "path/to/your/file.rs"
        repo.filter_commit(reformat_file, file_to_fix)
```

And running with `git filter-repo --path path/to/your/file.rs --replace-callback reformat.py`. Ridiculous complicated.



You want to rewrite each commit snapshot in isolation? Like fix the formatting for each?

Sounds like `git test fix` from git-branchless.

https://blog.waleedkhan.name/formatting-a-commit-stack/


>What I really want is to for git to treat each commit as a repository state, so that removing indentation from the state at commit A means that the patch for commit B adds all the indentation

`git rebase -X theirs` seems like it should be close, but commit B will only override conflicting chunks (so a change from A which doesn't conflict with B will persist, this shouldn't be a problem for your use case)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: