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.

3
  • Duplicate: stackoverflow.com/questions/14174757/… Commented Jun 30, 2016 at 19:55
  • But do you need to be removing everytime it or just for now? Commented Jun 30, 2016 at 19:55
  • It depends if you want to purge their history, or just remove them from the project. Commented Jun 30, 2016 at 19:59

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
You need to git push before that commit will be in your project_master repository.
Also, these types of files should go in a gitignore, which is normally committed to the root folder of your repository.
will definitely try gitignore.
Thanks for the answer and the helpful comments.
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.

1 Comment

strange. the 2nd method now works too, and it didn't say Everything up-to-date this time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.