1

I have just started to use git today.

I have a repository in project_master/project folder. I made that with git init --bare.

Then, I cd to project_work, and git clone ../project_master/project

I did some changes to the repository in project_work/project. Type make test. Didn't type make clean. After that, I git add everything, git commit, and git push origin master.

Now all the .o, .a files of the unit tests get into the repository in project_master/project folder. How to delete those .o, .a files from the repository in project_master/project folder?

Thank you.

Update:

I did the following:

~/project_work/project
cd unit_test
git rm *.o
git commit
git push origin master

Then,

cd ~/project_test
rm -rf project
rm -rf .git
ls -a
git clone ../project_master/project
cd project/unit_test

And the .o files are still there.

I also did as in this SO question: Completely remove files from Git repo and remote on GitHub. But didn't work. After that, I try git rm again and that didn't work.

Community
  • 1
  • 1
rxu
  • 1,369
  • 1
  • 11
  • 29

2 Answers2

2

You can use git rm *.o to stage their removal from git. Then use git commit to create the commit to remove them, or git commit --amend to amend the last commit that added these files and remove them from it.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • I did that before asking this question. After that I clone the repository in `project_master/project` to a folder call `project_test`. I found that those .a files are still there. After I type those commands. I typed git push origin master. and also git push. both commands says Everything up-to-date. – rxu Jun 30 '16 at 19:54
  • 3
    You need to `git push` before that commit will be in your `project_master` repository. – mkasberg Jun 30 '16 at 19:56
  • 2
    Also, these types of files should go in a [`gitignore`](https://git-scm.com/docs/gitignore), which is normally committed to the root folder of your repository. – mkasberg Jun 30 '16 at 19:57
  • will definitely try gitignore. – rxu Jun 30 '16 at 20:13
  • Thanks for the answer and the helpful comments. – rxu Jun 30 '16 at 20:30
1

There are two common approaches:

1. Remove locally then update git

rm filename(s)
git add -u .
git commit
git push

2. Use git itself to remove the file

git rm filename(s)
git commit
git push  

End result is the same, second approach is easier to use.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
  • strange. the 2nd method now works too, and it didn't say Everything up-to-date this time. – rxu Jun 30 '16 at 20:27