-1

Basically i added the env/ by mistake and committed then noticed once the push was taking forever and quickly stopped it.

How can i undo my env/ add?

Kelly
  • 153
  • 1
  • 2
  • 8
  • The kosher answer: `git revert HEAD`. Less kosher and really only if you haven't shared this with anyone else yet: `git reset HEAD~` – Ondrej K. Jul 10 '18 at 15:34
  • what does kosher even mean. – Kelly Jul 10 '18 at 15:37
  • Ah, sorry: https://en.wiktionary.org/wiki/kosher. And I take it your `remote` did NOT get updated? Also I assume you have no further commit on top. You could still do `git rebase -i` I guess if you did. – Ondrej K. Jul 10 '18 at 15:41
  • 1
    Possible duplicate of [How to undo the most recent commits in Git?](https://stackoverflow.com/questions/927358/how-to-undo-the-most-recent-commits-in-git) – phd Jul 10 '18 at 20:13

1 Answers1

2

If you interrupted the push, the odds are the remote wasn't updated; but the first thing to do is to verify that (and make sure the remote is in a consistent state). I'd expect it to probably be ok, but at least I'd do a simple check. For example, if you were pushing to master you could

git fetch
git log origin/master

and make sure it is still pointed to a commit that doesn't include your changes.

If that's good, then you can safely edit the history of your local branch and then re-dp the push.

If only the most recent commit was affected, you can

git rm --cached -r env
git commit --amend

If earlier commits were also affected, then you might want to use git filter-branch with an index-filter. This is a little more involved, so you'd want to consult the git filter-branch docs (which spell out examples of solving problems just like this).

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52