Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a file from Git Pull Request

I have a pull request opened where I have some project.lock.json files which I do not want to merge while merging my branch to main branch. Is there a way to remove thos project.lock.json files from my Pull Request?

like image 237
tavier Avatar asked Apr 21 '16 07:04

tavier


People also ask

Can I remove a file from a pull request?

Now, if you have write permission, you can click on the 'trash' icon for a file right in the pull request's “Files changed” view to make a commit and remove it.

How do I remove a file from git?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.

How do I delete a single file from PR?

If the unwanted updates are in an entirely new file that you created, then you can delete the file from your file system, then run git rm <file path> followed by git commit to remove the file from the PR.

What does deleting a file from a pull request do?

It does delete the file. It DOES NOT mean it will remove your changes to the file.


3 Answers

Please do let me know if there is a better way of doing this. This is the workaround I have found.

list remote branches

git branch -va

checkout the PR branch

git checkout origin pr_branch

overwrite pr_branch's file with other_branch's file

git checkout other_branch -- ./path/to/file

commit changes

git commit -m "overwrite with other_branch's"

push your changes

git push origin pr_branch
like image 93
Shiyason Avatar answered Oct 29 '22 03:10

Shiyason


You need to remove file, commit changes and make next push to your branch.

If you want leave file in your branch, but not to merge it to main branch, you can delete it in one commit, then add again in another. Git allows you manually accept certain commits using git-cherry-pick. You can accept each commit except that in which you have added this file again.

like image 44
Factory Girl Avatar answered Oct 29 '22 04:10

Factory Girl


I think you can simply override your project.lock.json with the origin one and commit.

like image 37
kofifus Avatar answered Oct 29 '22 05:10

kofifus