user12450543
user12450543

Reputation:

To undo git commit and get the remote files copied back replace the local

how to undo git commit and get the remote files copied back replacing the modified local files intended to be push but needs to be canceled and undone? (watch the plural)

Upvotes: 0

Views: 148

Answers (1)

Trinh Nguyen
Trinh Nguyen

Reputation: 57

  • Your modified local files can be discarded with stash command (git stash save --include-untracked, option --include-untracked for new file). This action will store all changes in repo in stash list.
  • If you have a commit but it is wrong, you can undo it by reset command. Example: you have 3 commits A - B - C, the current commit is C and you want to remove C, back to commit B, you can use: git reset <B-commit-hash>. reset have 3 options:
    • hard: all change in commit C will be discarded
    • soft: change of commit C will be in the staging area
    • mix: change of commit C will be in the working directory, mixed with current change (if any).

After reset, your local repo has B commit as the latest commit. This time, your local repo can be different from the remote repo.

  • If you sure this work fine, you can push to remote with git push --force. force option will override the history commit-graph same as your local repo.
  • If you want to update your local repo same as the remote repo, you can use git pull

I hope it's helpful for you

Upvotes: 1

Related Questions