The modifications from that reset-ed commit may be left as modifications in the working directory after HEAD is moved onto the parent commit, depending on
git reset --mixed
(default)git reset --hard
git reset --soft
restore
removes modifications in the working directorygit status
suggests how to do restorerestore
removes modifications from the staging areagit status
suggests how to do restoreEach commit gives defines file modifications, insertions/deletions (“patch”), between itself and the parent commit
For instance, if branch bugfix59 fixed two bugs in two different commits, we can “cherry-pick” the commit that fixes only one of the bugs and apply it onto the current branch.
Example: a bug was inserted with a commit long time ago. We have released several versions since then, we now wish to create a new commit that reverses the insertion of the bug.
rebase
is an alternative to merge, to avoid merge commits and instead maintain a linear history
Images: credits to https://git-scm.com/book/en/v2/Git-Branching-Rebasing
git checkout master
git merge experiment
$ git checkout experiment
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: added staged command
$ git checkout master
$ git merge experiment # now a fast-forward merge!
Thanks to the fast-forward merge, we have now a simple linear history
Remote repositories are distinct git repositories that share some commit history
git pull origin main:main
main
on her laptopgit push origin main:main
Dear Alice and Bob,
Thanks for your work on your laptop on feature4
and bugfix58
.
In the meantime, our main
branch on the central github repository has integrated changes from Caroline. Please pull these new changes and rebase your work; when done, please open a pull-request on github so we can review and merge your work.
You will find some work by Jerry on the github repo in branch doomed
. This leads nowhere so we will throw away most of the code in that branch. We only need the modifications in the commit Quickfix to be integrated in our main branch. Please cherry-pick that commit (only this one) from Jerry’s doomed
branch, and create a new quickfix
branch with corresponding pull-request on github.