0

I'll start by saying that I use git for source code control in Visual Studio Code, but have very little understanding about how it works beyond doing commits and restoring older versions.

I have developed an application in Flutter using Visual Studio Code, let's call this app. I have realised that my design choices have not been great and my best option is now to build a new app top-down taking selected code from the old app, and addressing the bad design choices I have made as I go.

To start this process, I have renamed my old app to appold following the guidance here, and then created a new Flutter project called app (i.e. I have used the same name as the original version of my application) using flutter create app at the command prompt.

When I open the new app folder in Visual Studio Code, the source control function shows that I have several hundred unsaved changes, which are all the missing files from appold (the new app is an empty Flutter project).

If I open a command prompt, go into each project folder (app or appold) and enter the command git log, I get the same output in each case, i.e. I get a list including all the stored changes to the original application.

Based on what I have read online, everything for git is stored in a .git folder in the project folder (i.e. it is a local database/repository), but what I am seeing suggests that there is a shared git database/repository somewhere and my re-use of the original application name for the new application is causing me problems.

I have looked at the answer here for renaming/moving a repository, but this doesn't seem to provide an answer to my particular problem, but that might be due to my lack of understanding.

I have gone into each of the .git folders and changed the entries in the description files to contain the respective project names app and appold. This hasn't made any difference.

Probably also worth mentioning that, to the be best of my knowledge, I haven't uploaded any of my code to the internet, e.g. github. I have tried to avoid this because I do not want or need the code to be online. I have checked my github account online and can't see any of my app changes in there.

Given my situation, how do I stop the new app project seeing the repository for the old version of the application, but use a new, empty repository instead?

Twelve1110
  • 175
  • 12

1 Answers1

1

It seems that your new app is still linked to the original Git repository. That's why git log gives the same results for both the app and appold folders. If you want to start a new Git repository for your new app, you need to delete the .git folder in your new app directory, and then initialize a new Git repository.

Here's what you should do:

First, navigate to the new app directory in your command prompt or terminal.

cd path_to_your_project/app

Delete the .git folder in your new app directory. You need to ensure that you're in the correct directory (the new app folder) because you don't want to delete the .git folder from appold.

rm -rf .git

Now, you can initialize a new Git repository in your new app directory. This will create a new .git folder, and the Git history will be empty since it's a new repository.

git init

After these steps, you should have two separate Git repositories: one for appold and a new, empty one for app. Then add and commit changes.

samgi
  • 198
  • 11
  • Thanks! That has worked perfectly. Just for my own learning, do you know why the new app git repository was linked to the old app repository? Is there maybe something happening in the VS Code plugins based on the app name? – Twelve1110 Jul 09 '23 at 13:12
  • @Twelve1110 it's hard to tell exactly the reason without knowing all details of your project setup, but it's likely that the process you followed to create the `app` project copied the .git folder from `appold` – samgi Jul 09 '23 at 15:59