简体   繁体   中英

How can i undo a git add after the commit?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM