5

I got a Git repository that I accidentally pushed a file 4 commits ago that is located in (path relative to the repository root folder): /Core/C:/testoutput/agwqe1s.xml

I did this on my Linux machine, so the actual file was created without any problem. The thing is when I go back to my Windows machine, I can't switch to the branch that has this file because the Windows just refuses to create such a folder. Ok, no problem, I deleted the file on my Linux end and commit it, but even tough it's not working. Git still tries to create this illegal file on my Windows machine, and I don't know what to do.

I know that I could remake the repo from scratch, but then I'd lost my whole commit log history, and I wanted to avoid that. What are my options over here?

2
  • Not familiar with git, but thought you must delete C: folder and all its children (folder & files). But you wrote, that "deleted the file". Commented Nov 1, 2012 at 18:29
  • I deleted the file and the folder. Git doesn't store empty folders. Commented Nov 1, 2012 at 18:46

1 Answer 1

6

you don't need to checkout that branch to update it. From a branch that works do this:

git fetch git push . origin/problembranch:problembranch git checkout problembranch 

the trick is to push to the same repository. That's what the . is for.

Sign up to request clarification or add additional context in comments.

5 Comments

The branch is updated, the problem is that when I try to checkout to the branch, what happens is: Invalid argument /Core/C:/ because that's an illegal filename.
update the branch in Linux. Push it up. Fetch it on windows while on a different branch. Only checkout the branch after doing the push command I posted.
Didn't work. I did this git filter-branch --index-filter 'git rm --cached --ignore-unmatch FILENAME' \ --prune-empty --tag-name-filter cat -- --all got this solution from stackoverflow.com/questions/2254601/bad-commit-to-git Thank you for your time @AdamDymitruk
which part didn't work. If you fetched successfully, the push would update the branch without it having to be checked out. Now that the branch points to a commit with a tree that doesn't have an invalid path, checking it out should work. The problem with what you have done here is that others may be caught off guard with changed SHA1s. My solution keeps them the same. All you do is add one commit to repair the damage. With yours, you can seriously harm a parent repo if this is a submodule. I'm adding this for completeness if others are considering the same thing with this problem.
I did it wrong, you're right, it worked. And the solution I posted can seriously harm the repo if done wrong.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.