Forum Discussion

Oimat's avatar
Oimat
Helper I
1 year ago
Solved

Git and PBIR mixes everything

Hello, 

In my git folder, I have multiple subfolders containing pbir files. Every time I merge a branch into another one, parts of json from a pbir gets mixed in the json of another pbir. Every time I merge into develop, I hence have to rewrite some jsons by hand.

 

Why does this keep happening ?

Today I even have a file that got corrupted that I was working on yesterday. It got corrupted in every branch/commit, and cannot do anything to get it back. 

 

Why does this keep happning ?

How to prevent git to mix all my jsons together from different folders ?

 

Thank you

  • Okay, I think I found the solution.

    I should stash my files before changing from one branch to the other, otherwise changed files from reports go populate other branches too and create thousands of conflicts.

    I'll have to do a 

    git stash

    everytime before I do a

    git checkout

     

    With code projects I never had this particular issue, but with lots of json files from pbip the problem is increased thousandfold. 

3 Replies

  • v-dineshya's avatar
    v-dineshya
    Community Support

    Hi Oimat ,

    Thank you for reaching out to us on the Microsoft Fabric Community Forum.

     

    Please follow below things to fix the issue.

    1. One Report is nothing but One Git Repo/Submodule

    If you are managing multiple .pbir reports, store each .pbir in a separate Git repository or Git submodule. This ensures changes in one report don't affect another.

    2. Use .gitattributes to Prevent Auto-Merging

    You can tell Git not to auto-merge JSON files, and force manual resolution

    Create or modify .gitattributes at the root of your repo:

    gitattributes

    # Prevent Git from merging JSON files automatically
    *.json merge=ours

    Or, for PBIR structure specifically:

    gitattributes

    **/*.json merge=ours
    **/*.pbip merge=ours

    Note: This forces Git to favor "ours" (your current branch) instead of trying to auto-merge incompatible JSON.

    3. Use PBIP Instead of PBIR When Possible

    PBIR is a new format and still maturing. PBIP (Power BI Project) is better structured for source control because it's cleaner and more modular (especially if you are working from Tabular Editor).

    Note: If you're not already using PBIP (created with Save as Power BI Project), consider switching.

    4. Avoid Manual Merges Rebase or Fast-Forward Instead

    Try to Rebase feature branches onto develop instead of merging. Use fast-forward merges to avoid Git attempting to reconcile unrelated changes in JSON.

    bash

    git pull --rebase origin develop

    5. Use Git Hooks or CI to Validate JSON

    Set up pre-commit or pre-merge hooks to Validate JSON syntax (jq, eslint, or custom scripts). Reject commits that would introduce malformed JSON

    Recovering from Corruption:

    Once a file is corrupted across branches/commits, your only recovery path is, Identify last good commit (git log).

    Restore the correct folder using:

    bash

    git checkout <good_commit> -- path/to/your/file.pbir/

    Note: Then recommit that version and start clean.

     

    Please refer community threads.

    Solved: Power BI Git Integration - Everything is Gone - Microsoft Fabric Community

    Solved: Power BI GIT everything is suddenly uncommitted - Microsoft Fabric Community

     

    If my response has resolved your query, please mark it as the "Accepted Solution" to assist others. Additionally, a "Kudos" would be appreciated if you found my response helpful.

    Thank you

  • If you are managing multiple .pbir reports, store each .pbir in a separate Git repository or Git submodule. This ensures changes in one report don't affect another.

     

    That should not be the case anyway, as git should not merge files between each other. It seems to be a git issue not knowng how to solve jsons files, but I cannot find the problem anywhere. 

    I also am not going to create 10+ git repositories. And I mispoke, the file is in .pbip but I always get a banner saying that the file is using PBIR report format, which I don't know why.

  • Okay, I think I found the solution.

    I should stash my files before changing from one branch to the other, otherwise changed files from reports go populate other branches too and create thousands of conflicts.

    I'll have to do a 

    git stash

    everytime before I do a

    git checkout

     

    With code projects I never had this particular issue, but with lots of json files from pbip the problem is increased thousandfold.