0

I realize this isn't directly a coding question, but GitHub is widely used and I haven't seen how to do this, so I figured I'd ask as I'm trying to figure it out.

Using GitHub how do I go about backtracking a development branch to a previous push point?

For example, let's say I have a dev branch and I push faulty code, how do I backtrack to a previous point in that branch in the event I need to?

I'd prefer to see how to do this from the command line, but in the web UI is fine as well.

ViaTech
  • 2,143
  • 1
  • 16
  • 51
  • git and github questions are on topic, no problem. However, this question has been answered very thoroughly already, so you should please search before asking. – matt Feb 14 '19 at 02:20

1 Answers1

2

Assuming your branch with the bad commit(s) has already been published to GitHub, and other users may have already pushed it, then you typically would not literally rollback that branch. Instead, you would use git revert to functionally undo the bad commit:

git revert 1a7h3jxk       # where 1a7h3jxk is the SHA-1 hash of the bad commit

git revert actually adds a new commit which functionally undoes the commit you specify as a parameter. It also allows syntax for specifying a range of commits.

If you really want to formally "backtrack" your branch, you could do a hard reset to remove the bad commit(s). For example, to actually remove a single bad commit you could do:

git reset --hard HEAD~1
git push --force origin your_branch

But note carefully that doing a hard reset means that you are rewriting the history of your branch. This means you have to force push (read: overwrite) the version of the branch on the remote. As mentioned above, this option should not be used if anyone shared this branch besides you.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • This is exactly what I needed, not sure how my initial search didn't provide me with these answers, but this works for what I was struggling to figure out, thanks! I marked this as duplicate because I didn't want to delete an answered question. – ViaTech Feb 14 '19 at 02:51