CarlosT
CarlosT

Reputation: 181

Replacing Git files for new ones

I have created an Eclipse project from an existing Git repository.

It contains some sample documents and code, but i find it easier to delete them and start from scratch.

Will the old documents be deleted in the repository without any trouble the next time i do commit and push?

Upvotes: 1

Views: 1142

Answers (2)

Channaveer Hakari
Channaveer Hakari

Reputation: 2927

Follow the following steps :

NOTE : origin here refers to your remote project location.

Step 1 : From command line navigate to project directory where your working

Step 2 : In command line run the following commands

   git pull origin master /* Just to make sure you will get all the latest files from remote repository where you have hosted your project */

   git rm * /* To remove all the files from you current directory */
       OR
   git rm file1.txt file2.txt /* to remote specific files */

   git add . /* Add the deleted files for staging */

   git commit -m "Removed obsolate files" /* Commit the deleted files into your local repository */

   git push origin master /* Now push to the remote repository all the changes that you have done, all the deleted files will be now removed from remote repository */

Step 3 : Now you can start working with your fresh files

Upvotes: 1

Ondra K.
Ondra K.

Reputation: 3077

If you want to delete a file, use git rm ${fileName} (in case you want to delete in only in git, but keep it locally, use the --cached flag. After that, once you commit and push, the changes will be available in the repo.

Upvotes: 0

Related Questions