0

I'm using Visual Studio Premium 2013 Update 5 to manage a Solution consisting of several projects. My last successful commit to Visual Studio Online was the evening of October 18th. My computer rebooted the morning of the 19th and installed a bunch of Microsoft updates. I did some minor development work on the 19th. When I went to commit my changes, I noticed that the Commit option was not available when I did a right click on the Solution within Solution Explorer.

Upon investigating why I can't do a commit, I noticed the following behavior. I open a file, make a change and the red check appears next to the file name and the file appears under Included Changes. When I save the file, the red check disappears and the file disappears from Included Changes. Since there are no changes being tracked by Git, there is nothing to commit to Visual Studio Online. I also noticed the the Git repo (/Portal) for the Project was missing from the Team Explorer - Manage Connections - Local Git Repositories section.

I then opened another Solution using Visual Studio 2015 Ultimate Update 3 and I noticed my Git repo (/Portal) under Manage Connections. I was then able to do a Git Status and found the following issue. See image below.

Command Prompt

Since my Git repo (/Portal) was missing, I went ahead a Cloned the Solution again using Visual Studio 2013. Visual Studio created a new Git repo (/Portal 2) and it now shows my original repo (/Portal) as well. My recent changes are still missing from Included Changes, so it's still not working correctly.

At this stage, I'm not sure if the corrupt file is the issue or if Update 5, which was downloaded months ago, but appears to have been installed on the 19th or 20th is the issue.

UPDATE 1:

Asked to run git fsck. Here are the results.

Command Prompt showing git fsck results

UPDATE 2:

Based on the code_fodder comment, I went ahead and tested making a code change using the new repo (/Portal 2). It works as expected. I made a change to a file and the red check still displayed after I saved the file. I also ran Git Status and there were no reported issues.

UPDATE 3:

The last statement (git push -u origin share) produces the following error.

Command Prompt showing git push -u origin share

The Share branch is missing from the Git UI as well.

Git UI image showing only the Master branch

Any help is much appreciated.

Dumber_Texan2
  • 840
  • 2
  • 12
  • 34
  • Did you try running `git fsck`? – Daniel Mann Oct 21 '17 at 18:56
  • I just ran it. Please see Update 1. Thanks! – Dumber_Texan2 Oct 21 '17 at 19:49
  • I always found the visual studio integration a bit suspect. Can you re-clone it on the command line? `git clone `, and then try the git status... – code_fodder Oct 21 '17 at 21:33
  • @code_fodder I just tested the newly repo (/Portal 2) that I created using the Visual Studio UI and it seems to work. Git Status also reveals no issues. Seems like the corrupt loose object in the original/old repo (/Portal) is causing problems. – Dumber_Texan2 Oct 22 '17 at 16:06
  • The loose object corrupt issue was mainly caused by accident, you can refer related issues https://stackoverflow.com/questions/4254389/git-corrupt-loose-object and https://stackoverflow.com/questions/26599706/what-might-cause-a-git-error-corrupt-loose-object. And it's not the issue for VS2013 to track git repo changes. – Marina Liu Oct 23 '17 at 05:39
  • @Marina-MSFT Thanks for the comment, but how do I recover from this? – Dumber_Texan2 Oct 23 '17 at 14:31
  • 1
    I added an answer for recovering the repo, you can have a try. – Marina Liu Oct 24 '17 at 07:21
  • @Marina-MSFT Thanks for that! This seems really helpful. If I make these changes to the local (/Portal) repo, do I need to delete anything in Visual Studio Online? The reason I ask is that the file/tree in question is dated 10/18/17 at 11:06 pm. This is the exact same time as the last successful commit. Could this corrupt file have created a problem in Visual Studio Online as well or is it only a local issue? I think this would be important to know for everyone who experiences this issue. Also, I assume that I am to run all the statements in your answer using the Command Line tool. Correct? – Dumber_Texan2 Oct 24 '17 at 16:40
  • 1
    It's a local issue. It works as recovering the corrupt commit on the top of your latest commit. Such as the last commit was `A` before the the local repo corrupted when tried to commit changes for commit `B`. After that, even your remote repo has new changes commit `C` (latest commit for now), the action aim to recovery changes as commit `B'` after latest commit `C`. And the commit history will look like: `..---A---C---B'`. And yes, the commands should execute by git command Line (such as cmd, git bash etc). – Marina Liu Oct 25 '17 at 06:54
  • @Dumber_Texan2 And I also added the illustration in my answer :) – Marina Liu Oct 25 '17 at 07:02
  • @Marina-MSFT The corruption occurred in the share branch. There are currently two branches. One is called master and the other is called share. Does this change the Git Command Line statements at all? Also, should I rename the .git folder or remove it? I could do ren .git .git-old and then if everything works successfully run rm -rf .git-old as part of the cleanup. Would you recommend that? Thanks! – Dumber_Texan2 Oct 25 '17 at 17:44
  • It's ok for the other branch `master`. After remove the old `.git` folder and create and fetch the new one from remote, the history for `origin/master` branch is recovered, you can double check by `git checkout master`. – Marina Liu Oct 26 '17 at 08:53
  • It's ok for the `master` branch.And one thing to note: since the corrupt object was happened on `share` branch while the new initialed repo's branch name is `master`. After execute the commands, you can rename the local `master` branch by `git branch -m share`. And double check your remote master branch by `git checkout master`. – Marina Liu Oct 26 '17 at 09:01
  • @Marina-MSFT I'm stuck on the last step. Please see Update 3. Also, I'm using Command Line on Windows 10. I had to use this statement rmdir /s /q .git and this one too git commit -m "recover the last commit before the repo was corrupted". Please advise. Thanks! – Dumber_Texan2 Oct 28 '17 at 18:24
  • @Dumber_Texan2 Please check in the remote repo in VSTS, if the share branch exist, and did you set branch policy or branch security for `share` branch? – Marina Liu Oct 31 '17 at 08:02

1 Answers1

1

If you didn’t change any files after the object was corrupt, you can recovery the local repo (/Portal) back. Detail steps as below:

#In the directory for Portal
rm  -rf .git
git init
git remote add origin <repo URL> -f
git reset origin/share
git add .
git commit -m 'recovery the last commit before the repo corrupt'
git push -u origin share

Now the last time changes has been recovered and pushed to remote share branch.

Note: the local master branch actually tracking origin/share branch. In order to make thing easier, you can rename local master to share branch by git branch -m share. And to check the history for your remote master branch, you can use git checkout master.

And the recovery commit just on the top of your latest commit (no issue with remote repo). Illustrate as below graphs:

Assume commit A was the last commit before the local repo corrupted when tried to commit changes as commit B. After that, even there has new changes in your remote repo commit C. The commit history on remote repo as below:

...---A---C   share

After you execute above commands, the recovered commit B' will on the top of the latest commit C. So the commit history will be:

...---A---C---B'   share
Marina Liu
  • 36,876
  • 5
  • 61
  • 74