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?
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.
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
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.
I think you can simply override your project.lock.json with the origin one and commit.
If they are already committed, there is no easy way that I can think of. Probably the easiest way, and a kind of work around, is to move them out the project folder, remove them from your git working copy, recommit so your branch doesn't have the JSON files in them. Then when you merge your JSON files won't go across.
You can checkout master and pull and then rebase your branch against master and rebase master to make sure you've removed it only from your PR but not from the repo so when you merge onto master it will not remove those files but only from your PR.
git checkout master
git pull
git checkout <your-branch>
git rebase master
git push
First, find out the specific commit that affects that file. Then the below two commands should revert the commits to that file.
git revert <commit>
git push origin <branch name>
- copy the files from origin repository. And Overwrite the files in your branch's repository.
- Make a commit.
- Go to pull request's "Files Changed" page, there will be an option to refresh. Or refresh the page manually.
I know this question is old, but I had exactly the same problem (a weasley YARN config file ended up in my commit without me noticing and ended up pushed to the remote and in a Pull request before I noticed
Eek.
Luckily I found this:
Git: Remove committed file after push
What worked for me was this:
git rm --cached /path/to/file
git commit -am "Remove file"
git push
It's clear, straightforward and doesn't involve complex and worrying HEAD^ commands.
To be clear, this creates another commit with the offending file removed - which is fine, although you will want to do this before the branch is merged with another - e.g. master.
Hope this helps.
© 2022 - 2024 — McMap. All rights reserved.