-1

I try to push my changes to a remote repo, but I keep getting the following error:

My git command:

git push --set-upstream origin MyNotYetExistingOnline/Branch

The output:

Enumerating objects: 33, done.
Counting objects: 100% (33/33), done.
Delta compression using up to 20 threads
Compressing objects: 100% (29/29), done.
Writing objects: 100% (29/29), 7.01 KiB | 2.34 MiB/s, done.
Total 29 (delta 20), reused 0 (delta 0), pack-reused 0 (from 0)
error: remote unpack failed: error The tree object 85215f8e6fd75c064be11175c96a98f352317750 was rejected: The file 'clsSqlServerAccess.cs' and the file 'clsSQLServerAccess.cs' pushed differ in case. You must remove or rename one of them or disable case-enforcement (see https://aka.ms/git-platform-compat).
To https://dev.azure.com/AzureDevOpsRepo
! [remote rejected] MyNotYetExistingOnline/Branch -> MyNotYetExistingOnline/Branch (The tree object 85215f8e6fd75c064be11175c96a98f352317750 was rejected: The file 'clsSqlServerAccess.cs' and the file 'clsSQLServerAccess.cs' pushed differ in case. You must remove or rename one of them or disable case-enforcement (see https://aka.ms/git-platform-compat).) error: failed to push some refs to 'https://dev.azure.com/AzureDevOpsRepo'

I already name one of the files to clsSqlServerClass.cs and commited! I still get this error.

Why is that? How can I get rid of this error?

13
  • 2
    Try git show 85215f8e6fd75c. My crystal ball says that you have both files clsSqlS... and clsSQLS... in the tree object. Remove one of them. Commented Aug 28 at 10:02
  • Yes, you're right, I have both objects in that. How do I remove one of them? Is it just git rm clsSQLServerAccess.cs? Or should I put the tree object hash behind the git rm-command? Commented Aug 28 at 10:13
  • 1
    git rm --cached clsSQLServerAccess.cs should do it. Then follow up with git status to see what happened. Commented Aug 28 at 10:27
  • This results in an error: fatal: pathspec 'clsSQLServerAccess.cs' did not match any files. I copied the file name out of the object tree... Commented Aug 28 at 11:03
  • 1
    git rm doesn't affect the tree object directly, but the staged file. You must supply the path where the file is located: git rm --cached path/to/clsSQLServerAccess.cs. Commented Aug 28 at 11:22

1 Answer 1

2

Option 1: Disable the Setting

Since you didn't mention it explicitly, I'd like to draw your attention to what the error message says:

You must remove or rename one of them or disable case-enforcement (see https://aka.ms/git-platform-compat).

The page linked to in that message explains why the check exists, and links to another page which explains how to turn it on or off.

Option 2: Rewrite History

If having read Microsoft's explanation, you want to keep the "Case Enforcement" setting on, you'll need to sort out your repository before you push.

When you push to a remote, you are not only pushing the current state of a branch, but every commit in its history. If you delete or rename the file, and create a new commit, git still needs to know what it was called in "previous" (ancestor) commits. And anyone cloning the repository can check out any of those commits, so the "case enforcement" will apply to them all.

So, to solve your problem, you need to "rewrite history" - create an altered version of the branch where the file never had the conflicting name.

How to do that depends how many commits and branches need to be changed:

  • If the file was only introduced in the most recent commit, you can make changes as normal, then instead of a normal git commit use git commit --amend to replace the currently checked out commit with a new one.
  • If the file was introduced on the current branch, a few commits ago, you could use git rebase --interactive to amend multiple commits in the same way. Interactive rebase is a powerful but sometimes confusing tool.
  • If there are several commits in your history that need fixing, maybe even in multiple branches, you can use git-filter-repo, which offers a --path-rename option. This will go through every reachable commit in your repository, and create a commit where everything is the same except for this file name.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.