I mistakenly used git commit -a and added more files than I wanted to in a commit. There was another modified file that I wanted to add as a separate commit included in this commit. How do I go back ( without losing the modifications to the files ) and then commit them all again separately.
I've also pushed this to a remote origin ( though I know for a fact that no one has pulled anything since I pushed).
Many Thanks!
If this is your last commit and you want to completely delete the file from your local and the remote repository, you can: remove the file git rm <file> commit with amend flag: git commit --amend.
In order to delete a remote Git tag, use the “git push” command with the “–delete” option and specify the tag name.
Warning, this will overwrite the changes remotely. If anyone has taken down the current commit and worked on top of it, bad things could happen.
# Reset last commit, but keep changes staged
$ git reset --soft HEAD^1
# Unstage unwanted file(s) and recommit
$ git reset HEAD path/to/file
$ git commit
# Push the new commit with force to overwrite changes
$ git push origin -f
You can just remove these files locally and push a new commit.
If you like to excude these files in future you can add it to .gitignore file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With