Need help on how to remove a file from a PR

I suggest you give the docs a read first when you have a question about a command line utility. Generally you can replace all other options with --help to display the documentation.

git push --help

Try running the above and scrolling down to the explanation of the -f, --force option.

But to put it plainly, you’ve already pushed your local branch up to the remote repository on GitHub. If you make further commits locally and push again, git is, by default, going to make sure the history of your local branch matches that of the remote branch before allowing the push. So if you were to change the history of your local branch via reset and try to push again, git won’t let you.

But in a case like yours, where you’re certain that you and only you are working on the branch, then you can tell git to just do it with the --force option on git push.

Am I supposed to see the files back as they were when using git reset HEAD, because I don’t? And the files are as they were after I changed and pushed them using --hard:

PS C:\Users\14844\Documents\WebDev\repos\freeCodeCamp> git reset --hard HEAD
HEAD is now at 918418c2b5 fix(curriculum): typos in Beta Registration Form
PS C:\Users\14844\Documents\WebDev\repos\freeCodeCamp>

Looks like git reset <commit_hash> worked.

Yes :slightly_smiling_face:

Let us start from the top:


This is what I would have done, were I the one who made the changes/PR you did:

Terminology

  • upstream - freeCodeCamp/freeCodeCamp (on GitHub)
  • origin - Kernix13/freeCodeCamp (on GitHub)
  • local - on your PC
  • <repo>/<branch> - notation to refer to a repo (location) and branch name
  • <branch>$ - notation to refer to what branch I am on in my shell/terminal
  1. Update local branch with upstream
main$ git fetch upstream
  1. Update local/main git history to match latest from upstream/main
main$ git reset --hard upstream/main
  1. Update origin/main with updated local/main
main$ git push origin main --force
  1. Create a new branch with the same Git history as local/main, and check it out
main$ git checkout -b fix/rf-typos
  1. Make too many changes, and add them to Git’s staging
fix/rf-typos$ git add .
  1. Commit what is in staging to the history with a commit message
fix/rf-typos$ git commit -m "fix(1)"
  1. Push local/"fix/rf-typos" to origin, and create origin/"fix/rf-typos"
fix/rf-typos$ git push --set-upstream origin fix/rf-typos
  1. Open PR using GitHub UI on upstream

  2. See that I have been requested to remove most changes. Reset local/"fix/rf-typos" to state it was before I committed any changes:

fix/rf-typos$ git reset --hard <commit_hash_from_before_my_changes>
  1. Confirm that the changes I made are no longer on local/"fix/rf-typos"
fix/rf-typos$ git log
  1. Make changes, and add to staging
fix/rf-typos$ git add .
  1. Commit with message
fix/rf-typos$ git commit -m "fix(2): ..."
  1. Force push to local/"fix/rf-typos"
fix/rf-typos$ git push --force

That should be all is needed.

Hope this helps

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.