King Wilder
King Wilder

Reputation: 659

Replace remote git repository

I don't know how typical this is, but it's something I need to do, is replace part of the local repository.

I've started git repository in Team Foundation Server (TFS) that contains a Visual Studio Solution with several projects. The structure is similar to this in Visual Studio:

Solution Folder (root)
|
|- WPF
|
|- C# services
|
|- Angular App // <-- I want to replace just this 

The Angular app in the remote repository has bad code and it's been rebuilt from the ground up. I need to completely replace the Angular App part of the git repository only!

What is the best way to do this? Again, the rest of the Visual Studio solution has to remain untouched and working.

I would prefer that the previous version of the Angular app is gone in the remote repository before committing any new Angular files.

Can I do this by simply removing all Angular files in my local folder, and then doing a 'git push', which should delete all Angular files since nothing is in the local folder?

And then can I copy my new working Angular application into the local folder, and do another 'git push', which should commit all the new Angular files to the same existing remote repository?

The bottom line is that I cannot keep any files from the previous Angular app.

Upvotes: 0

Views: 107

Answers (1)

Daniel Mann
Daniel Mann

Reputation: 59035

Yes, you can just delete the files, commit the deletion, and then push the change to the remote. That will eliminate the files.

However, the history of those files will still be in the repo. That's correct and normal behavior.

If you need the history removed as well, you can rewrite the past commit history (using filter-branch or a dedicated history rewriting tool like BFG) to eliminate them. However, this is a disruptive operation as the rewritten commits will have new hashes assigned to them, resulting in everyone needing to re-clone the repo. Personally, I wouldn't bother.

Upvotes: 1

Related Questions