'How do I deal with the array out of bounds exception when creating a new git branch from a past commit in Visual Studio?
Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
This is what I get in the Team Explorer tab when I try to create a new branch to one of the previous commits. I've had this error happen in the past, and updating to the most recent version of VS 2017 (15.9.7) just now made no difference. In the past the only way I've managed to get around this problem is by branching out to some other commit, but now this really hit me where it hurts.
Solution 1:[1]
Using git checkout from the command line worked for me.
More specifically, git checkout <commit> -b temp where <commit> is the commit id. What this did is create a branch named temp similarly to how it would be done using the IDE.
I have no idea why this error occurs for me, but while looking at similar issues I noticed that people managed to get around using git commands from the command line. It worked fine enough here.
Solution 2:[2]
It's due to overload of commits cache in local, since it's specific to Visual Studio
- Option 1 : use git bash git checkout
- Option 2 : Take a local repo backup, delete it and clone it one more time
Solution 3:[3]
I had this error and I made the following steps: Go to: Visual Studio -> Team Explorer -> Branches Step 1: Remove the local Branches that you do not need any more Step 2: on each remaining local Branches I right click and select Reset -> Delete changes (hard)
Probably not need existing changes once you start to work on another branch.
Solution 4:[4]
In case anyone faces this problem in the future, just like I did and stumbled upon this thread, I share my scenario and how it was solved:
Scenario: We Squashed and merged a huge branch with integration branch which resulted in the top commit on integration branch to be a huge one (over 900 files changed). Once integration had this huge commit on top we were blocked from checking out to it (We got the same error like mentioned in this thread) and if we used command line/other git control to checkout to integration, we got this error also when we tried to create new branches from it.
This error happened on all our devices and on VS2019 + VS2022
Solution: Use git commands / another git control to checkout to the branch resulting in this problem. Commit and push a small commit message. It should go back to normal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Mysterion |
| Solution 3 | Cosmin Antohe |
| Solution 4 | M. Sakhnini |
