Delete file from Pull Request on GitHub

后端 未结 7 1162
误落风尘
误落风尘 2021-02-06 23:00

I have make pull request on git (with \"xcodeproj/project.pbxproj\" file - my fault), so can I delete this file from created Pull Request? Thanks..

相关标签:
7条回答
  • 2021-02-06 23:18

    To remove a file from your PR:

    git rm path/toFile/youwantRemovedOffyour/PR
    git commit -a
    git push
    

    To remove a directory from your PR:

    git rm -r path/toFiles/youwantRemovedOffyour/PR
    git commit -a
    git push
    
    0 讨论(0)
  • 2021-02-06 23:24
    • Make a commit that deletes this file and push it.
    • Go to your fork's Github page and click Pull Request again. You will get a message stating that you already have a pull request, and that you can adjust the commit range for it.
    • Include your new commit (with the deletion).

    The offending file will still be in the changesets to be merged, mind you, so if it contains sensitive data it's best to close the pull request and wipe out the file from your fork's repository first. Github help describes how to do that.

    0 讨论(0)
  • 2021-02-06 23:26

    Another solution would be to

    • Locally rewrite your commit(s) by removing the file, using amend or rebase git features
    • Force push your branch toward your GitHub repository

    This will update the pull request by only displaying your refreshed commit(s).

    0 讨论(0)
  • 2021-02-06 23:33

    New approach, since July 2018:

    Removing files from a pull request

    Previously, if you wanted to use GitHub to remove files from a pull request, you’d need to switch to the pull request branch and look for the individual file to delete it.

    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.

    Warning: as confirmed by RCM in the comments:

    It does delete the file.

    It DOES NOT mean it will remove your changes to the file.
    It is quite deceptively worded, in my opinion.

    0 讨论(0)
  • 2021-02-06 23:38

    You probably will merge this pull request on master, so you can checkout just this specific file again, from master, on your branch, just type:

    git checkout master -- xcodeproj/project.pbxproj
    git commit -m "removing a file from PR"
    git push origin {YOUR BRANCH}
    
    0 讨论(0)
  • 2021-02-06 23:39

    If all you want to do is just remove(delete) the changeset of a file that is already a part of the pull request, currently you can't do that via the web UI. You have to update the file locally and do a git push to the PR.

    0 讨论(0)
提交回复
热议问题