removing a specific file from a pull request

Hey all! New year, new post *ba dum tss*

So this week I was having a bit of a slow morning, and when creating a new pull request I did not realise that I included an already existing file by mistake. Thankfully, I realised that I was about to merge unwanted changes before the reviewer got a chance to look at my PR, but I was now facing another issue. Is there a way to remove just one file without deleting the whole pull request?

After a quick search I found a solution that suits my problem.😎👌
Check out on the branch that has your PR, replace the file with an unmodified version (of the same file) from a different branch (in my case master branch), commit the changes and finally push to the same PR. Git commands, to be typed in Visual Studio’s Package Manager Console, below.


git checkout branch-that-has-pr
git checkout origin/master — C:\somefolder\someotherfolder\thefile.cs
git commit -m "Removed a file from pull request"
git push origin branch-that-has-pr

Short and sweet, and works like a charm. Until next post,
Bjorn

3 thoughts on “removing a specific file from a pull request

  1. Thank you ! It works like a charm 🙂
    Step 2 will raise an error because of “— ” So you have to replace it with “–” (two dashes)

    Like

  2. Pingback: pull specific file or directory from a remote branch | It's not a bug, it's a feature

Leave a comment