I committed, but not pushed to repository, a file to a branch i.e. abc. Now I want to remove it from this branch abc. How can I achieve this?
I committed, but not pushed to repository, a file to a branch i.e. abc
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m assuming you want to obliterate the file from history, as if it never existed. If you just want to get rid of the file in future commits, then use
git rm my-bad-file.txtand ignore the rest of my answer.If the file is only in your most recent commit, then it’s easiest to use
git rm my-bad-file.txtto remove the file, thengit commit --amendto edit the previous commit.If there are several commits containing the offending file, then
git filter-branchmight be useful.This means:
git filter-branch: Let’s rewrite some commits!--index-filter: Change each commit’s index without actually checking it out on disk.'git rm --cached --ignore-unmatch my-bad-file.txt': For each commit, unstage the file named “my-bad-file.txt” if it exists.master..abc: Do this on all commits on branch abc back to where it forked from the master branch.