0

Search found How can I edit the .git / config file from the git terminal?. The answer tells e.g. to use editor of choice to edit .git/config. I'm currently investigating IMO strange behavior of git in my repo and suspect my manual edit of .git/config might play a role.

As of now I see many files in .git are text files expect objects (which AFAIK are "actual work files", delta's of them). However there are binary index and sometimes packed-refs. I recall reading packed-refs is used to speed up search (How to unpack packed-refs?).

Say:

git branch --set-upstream-to=origin/test
error: the requested upstream branch 'origin/test' does not exist 

But I can just edit config replacing main with test in merge = refs/heads/main. Also replace URL of remote (that I did many times), replace commit hashes in refs, add refs and folders with refs (say copy refs/remotes from other repo), add lines to .git/config, literally write/add/delete anything that is valid git syntax.

Can any of the above break some internal git repo consistency? If yes, is there an easy way to update repo to consistent state honoring my edits?

Martian2020
  • 307
  • 3
  • 12
  • Did you run `git fetch origin` first? – Ry- Dec 12 '22 at 23:14
  • @Ry, before manual edit? I don''t want to be required to do that (at least sometimes). I guess you misunderstood the question, which is more general, I have not found an answer to possibility of editing by hand of git config. If BTW as per SO rules questions should be specific, I think I can break it to several: for config URL, for merge, for refs. – Martian2020 Dec 12 '22 at 23:25
  • 2
    Unless you're using `git` or editing in things documented officially as things to edit, you're using the repository in ways it's not meant to. It may work. It may cease to work in the future. So, I believe the idea @Ry- suggests is a way to make the initial `git branch --set-upstream-to=origin/test` work. Generally, this sounds like a so-called "XY problem". – Ulrich Eckhardt Dec 12 '22 at 23:30
  • @UlrichEckhardt, you are generally right. I have several X (as related to this post). I'm investigating, hence I wanted to know dangers of manual edit to know what edits are safe and what are not (I recall I did some. don't recall exact;y what). I've posted 3 X recently (and think there are not completely resolved). As of now I'm trying to understand why `git branch --set-upstream-to=main main` in my repo resulted once in same output as `git branch --set-upstream-to=origin/main main` results now. I don't think posting that one w/out much details will help. – Martian2020 Dec 12 '22 at 23:49
  • @UlrichEckhardt, if you have some time to help with X, please see https://stackoverflow.com/questions/74778280/how-to-safely-not-to-brake-internal-consistency-of-the-repo-edit-git-config-an. TIA – Martian2020 Dec 12 '22 at 23:58
  • 2
    (I ignored the more general question because of the XY aspect; it’s vague and possibly unanswerable. The way you guarantee keeping your repo in a consistent state is by using the CLI designed to do that.) – Ry- Dec 13 '22 at 00:14
  • @Ry-, do you know how to convert repo made by `clone --mirror` (target) to tracking source with CLI? If you do please answer https://stackoverflow.com/questions/74778280/how-to-safely-not-to-brake-internal-consistency-of-the-repo-edit-git-config-an. TIA – Martian2020 Dec 13 '22 at 01:21
  • 1
    The `.git/packed-refs` file is ordinary text. There is a project to build a binary refs database (modeled on the one that already exists in JGit) but it's not part of (C) Git yet. – torek Dec 13 '22 at 05:01

0 Answers0