Refined-github: Remove file from PR

Created on 1 Apr 2019  Â·  9Comments  Â·  Source: sindresorhus/refined-github


Issuehunt badges

Basically a duplicate of #1127.

Sometimes in a PR file changes slip in that you didn't intend. Maybe you didn't correctly stash, a commit hook made a formatting change, or some other thing happened.

The ultimate result is that you want to undo changes to a particular file in your PR. It'd be nice to have a button on the header of every file in the diff to revert that change.

Something like this...

image

It seems like this was added in #1398, but it's no longer present or working now. At least not in the FF version of the plugin. GitHub added the trashcan icon to actually _delete_ a file... heh, I almost did that >_>.




IssueHunt Summary

fregante fregante has been rewarded.

Backers (Total: $80.00)

- #2182 Add revert-file feature

Tips

IssueHunt has been backed by the following sponsors. Become a sponsor


Rewarded on Issuehunt enhancement help wanted

Most helpful comment

They’re different.

“Delete file” fully deletes the files, it’s a feature that was added by GitHub.

“Revert all changes in file” is a feature that would indeed be nice to have, arguably this is the only button PRs need 👍

All 9 comments

They’re different.

“Delete file” fully deletes the files, it’s a feature that was added by GitHub.

“Revert all changes in file” is a feature that would indeed be nice to have, arguably this is the only button PRs need 👍

@bfred-it I would be more than happy to contribute to this. Can you point me towards the starting point? Thanks!

Honestly I don’t know if there’s an easy way to do this, you’d have to look the API for reverting

Yeahhh... I was looking into this. It's definitely non-trivial.

I think the easiest way to is to follow this path:

  1. Get the base branch of the PR
  2. Use the contents api to grab the base version of the file
  3. Use the contents api to create a new commit of the file as it was at its original state.
  1. Not the base branch, but the parent commit of the first commit in the PR. The base branch might have changed.
  2. Maybe you can skip this step if you can just checkout the file like you can in git: https://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git

GitHub's api doesn't really expose higher level git actions like checkout. We could use the commit api to try to replicate this process, but I'm not sure how to go about doing that.

The correct API seems to be Contents API

https://developer.github.com/v3/repos/contents/#update-a-file

Use it for steps 2 and 3

@issuehunt has funded $80.00 to this issue.


@sindresorhus has rewarded $72.00 to @fregante. See it on IssueHunt

  • :moneybag: Total deposit: $80.00
  • :tada: Repository reward(0%): $0.00
  • :wrench: Service fee(10%): $8.00
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexanderadam picture alexanderadam  Â·  3Comments

supremebeing7 picture supremebeing7  Â·  3Comments

fregante picture fregante  Â·  3Comments

Arcanemagus picture Arcanemagus  Â·  3Comments

olso picture olso  Â·  3Comments