sindresorhus/refined-github

Remove file from PR #1901

zephraph posted onGitHub

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...

<img width="1027" alt="image" src="https://user-images.githubusercontent.com/3087225/55346192-e6b96400-547f-11e9-90b7-031c9dc0d34e.png">

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 >_>.


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 👍

posted by bfred-it about 6 years ago

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

posted by HardikModha about 6 years ago

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

posted by bfred-it about 6 years ago

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.
posted by zephraph about 6 years ago
  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
posted by bfred-it about 6 years ago

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.

posted by zephraph about 6 years ago

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

posted by bfred-it about 6 years ago

@issuehunt has funded $80.00 to this issue.


posted by issuehunt-app[bot] almost 6 years ago

@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
posted by issuehunt-app[bot] over 5 years ago

Fund this Issue

$80.00
Rewarded

Rewarded pull request

Recent activities

fregante was rewarded by sindresorhus for sindresorhus/refined-github# 1901
over 5 years ago
bfred-it submitted an output to  sindresorhus/ refined-github# 1901
almost 6 years ago