Beyond the usual git commands, here's a compilation of some I found useful during my group's TP:
-git rebase -i HEAD~<how-many-commits>: Allows you to edit commits up to before the latest commit of your current branch. Change the first word before any commits(see highlighted words in screenshot below) from pick to edit to modify one or more commits' changes. Example screen of git rebase -i:
-git diff and git patch: If you have changes to transfer to another branch conveniently, do a git diff > changes.patch to generate uncommitted and unstaged changes, or git diff <another-branch> > changes.patch to generate all changes between current and . Then apply the changes in another branch using git patch changes.patch, assuming changes.patch is the output file from git diff earlier
-git reset --soft HEAD~<how-many-commits>: Uncommits the past <how-many-commits> commits but preserves all the changes as staged files in the current branch. You can then unstage changes/add changes and git commit again so that you can split up the changes into different commits, make additional changes, or anything else that may be useful
git revert <commit-SHA>: Undos the changes made in a specific commit(identified by the commit hash). This generates a new commit that is the opposite of the specified commit(undo changes), which can be helpful when you've already pushed changes to the remote repo and don't want to force-push to modify the commit history(which is not recommended).
Beyond the usual git commands, here's a compilation of some I found useful during my group's TP:
- before the latest commit of your current branch. Change the first word before any commits(see highlighted words in screenshot below) from
git rebase -i HEAD~<how-many-commits>
: Allows you to edit commits up topick
toedit
to modify one or more commits' changes. Example screen ofgit rebase -i
:-. Then apply the changes in another branch using
git diff
andgit patch
: If you have changes to transfer to another branch conveniently, do agit diff > changes.patch
to generate uncommitted and unstaged changes, orgit diff <another-branch> > changes.patch
to generate all changes between current andgit patch changes.patch
, assumingchanges.patch
is the output file fromgit diff
earlier-
git reset --soft HEAD~<how-many-commits>
: Uncommits the past<how-many-commits>
commits but preserves all the changes as staged files in the current branch. You can then unstage changes/add changes andgit commit
again so that you can split up the changes into different commits, make additional changes, or anything else that may be usefulgit revert <commit-SHA>
: Undos the changes made in a specific commit(identified by the commit hash). This generates a new commit that is the opposite of the specified commit(undo changes), which can be helpful when you've already pushed changes to the remote repo and don't want to force-push to modify the commit history(which is not recommended).