Need help on how to remove a file from a PR

Recap: I made a typo change to only 2 files in one of the RWD Beta sections. Using git status showed only 2 files both before and after using git add . But when I made the commit it showed 3 files. I took a screenshot of the console in VS Code which can be seen in the PR here fix(curriculum): typos in Nutrition Label section by Kernix13 · Pull Request #44652 · freeCodeCamp/freeCodeCamp · GitHub

Someone with the user name gikf commented that the file can be removed with an additional commit. You can look at the file added on the files tab but it looks like a bunch of command-line commands.

I did do one thing wrong: I used git fetch upstream on one of my branches instead of on main. Could that be the cause?

Regardless, how do I use a commit to remove a file that was in my last commit?

Are you using the VS Code UI to make your commits? Is the file tream showing up in the project’s root directory?

Hi @kernix !

I checked your branch and it does look like this tream file is in the project’s root directory like @colinthornton mentioned

Have you tried just manually deleting it in VS code?

Yes, it is in the root file. Did I do something to create it? I can delete it but it is in the commit I pushed.

I deleted it from the root folder. Can it be removed from my PR?

Now that you’ve deleted it you should be able to add the deletion to a new commit.

If you run git status you should see that the file has been deleted. Now you need to stage it with git add tream, etc. Then make a commit and push.

That was easier than I thought, thanks! But I’m not seeing the “Compare & pull request” button on my cloned repo page.

You were working on the same branch, so the existing PR was updated.

Nice - it’s gone from the files tab. So what is that file? Did I create it by accident?

Probably! Something you have installed maybe adds it to git directories automatically… Googling “tream” doesn’t come up with anything for me though. Hmmm. See below

Looks like it’s the less program help file? Seems you output it into a new file by accident. Something like this:

less --help > tream

less --help outputs the help file, and > tream redirects that output to a file called tream.

Be careful on the command line!

That’s it. I know right before that I tried git log but I did got instead of git. I also spelled another command wrong as well. I’ll slow down and be more careful and start looking for that file in my root folder.

Just make a habit to review your changes before committing them! On the git tab in VS Code it lists all the changed files so you can review them easily.


Glad you were able to fix it. :grinning:

1 Like

Didn’t know that - I’ll check that tab each time.

I clicked that tab and I didn’t see anything.

I am being asked to remove 8 of 9 of my changes for a different branch. I can make a new post, but would I do that similar to the above? 1. Make the changes, 2. Add, Commit, and Push and my original PR will be updated?

Hello there,

In general, you can use the git revert command to revert changes from previous commits:

git revert <commit_hash>

However, this will revert all the changes from that commit hash. So, if you only want to revert based on the file, it is also common to use git checkout:

git checkout <commit_hash> -- path/to/file

In this case, the commit hash is any hash when the file was in the state you want it to revert to.

Finally, if you are removing more than you are keeping, it could be worth resetting your branch to the point it was before the changes:

git reset <commit_hash>

Then, you can make the changes again, and force push to the same branch:

git push --force

I hope this helps some

Ok, so the last one sounds like what I want.

So if I use git reset <commit_hash>, make the one change that I am being told to keep, then do the normal add, commit, push origin my_branch_name., that will work? Should I do the last part on the same branch or should I delete that branch after the revert command and create a new branch?

Maintainers appreciate these two things in this priority:

  1. Related conversation is kept in a central location
  2. PRs are kept neat - easy to follow

At a quick glance, it looks like you should be able to do:

# You might need the --hard argument
git reset HEAD
# Make your wanted changes
git add .
git commit -m "fix(curriculum): what this does"
git push --force
# The above assumes you have set your branch to follow the remote branch on your origin

Assuming that, there should be no need for you to create a new branch, and there should be no need for you to create a new PR.

Hope this helps

PS: I am also talking to you on GitHub


PS: I am also talking to you on GitHub

Are you the one asking for the changes?

Regardless, should I use:

git reset HEAD


git reset HEAD --hard

Also, I’ve been using git push origin branch_name. Are you saying I only need to use git push --force?