Tuesday, 15 September 2020

Safely revert a commit and discard local change

// Revert everything to the <commit_hash_you_want_to_restore_to>  

// Rest commit local branch

git revert --no-commit <commit_hash_you_want_to_restore_to>..HEAD

// Push to remote
git commit
git push

https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit

// Revert current commit on local branch 
git revert --no-commit <current_commit_you_want_to_remove>
// remote current commit on remote branch 
git commit
git push

// revert a list of commit up to the<commit-hash > local branch
 git reset --hard <commit-hash>
// status check
git status
Your branch is behind 'origin/remote' by N commits, and can be fast-forwarded.
// revert a list of commit up to the <commit-has> forcefully to remote by using -f origin <remote>
 git push -f origin <your_remote_repo_name>
https://stackoverflow.com/questions/5816688/resetting-remote-to-a-certain-commit
https://stackoverflow.com/questions/24730127/git-commit-gives-error-empty-commit-set-passed

// Discard local change
git reset --hard
https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state


No comments:

Post a Comment