Git Reset:
Git Reset is a command used to undo changes to a repository by moving the branch pointer to a previous commit. This command can be used to unstage changes, discard changes, or even completely remove commits from a branch. Git Reset is a powerful command that should be used with caution, as it can alter a repository's history.
Git Hard Reset Vs Soft Reset:
Syntax:git reset --hard d69950b completely discards changes and sets the repository to the specified commit. This means that any changes made since the specified commit will be lost permanently. This command is useful for completely undoing changes or rolling back to a previous commit.
git reset --hard without specifying a commit hash, it will reset to the last commit and if you’ve made changes after the last commit, they will be reset.
git reset --hard HEAD^ reset the HEAD to the previous commit (one commit back). If you check the log, the previous last commit is gone now.
git reset --soft d69950b does not discard changes, but it does unstage them. This means that the changes will still be present in the working directory and can be committed again later. This command is useful for preparing changes for a new commit, or for "splitting" a commit into multiple smaller commits.
Git Revert:
Git Revert is a command used to create a new commit that undoes the changes made by a previous commit. This command creates a new commit with the opposite changes of the reverted commit, allowing you to undo changes while keeping a record of the original commit.
Syntax:
git revert 59c86c9 where 59c86c9 is the commit hash. You can find it from git log --oneline
Git Rebase:
Git Rebase is a command used to integrate changes from one branch into another by rewriting the history of the target branch. This command is used to create a linear history, rather than a branching history, and is useful for keeping a clean and organized Git repository. Git Rebase can be used to merge changes from one branch into another or to update a branch with changes from another branch.Syntax:
git rebase feature this is executed while on the master branch to incorporate commits that were in the feature branch to master and make the timeline linear.
In summary,
Git Reset is used to undo changes to a repository by moving the branch pointer ← Don't use this if you don't want to cover the track because this doesn’t leave a mark of what you were doing.
Git Revert is used to create a new commit that undoes changes made by a previous commit ← USE THIS to revert a commit.
Git Rebase is used to integrate changes from one branch into another by rewriting the history of the target branch
Credits
Images: geekflare.com
No comments:
Post a Comment