In dedication to my awesome colleagues at Ahold, I hereby present some of the most frequent questions asked questions about git.
Help, I broke my code
Help I broke my code and just want to get it to work again! All changes I’ve made are allowed to be discarded.
$ git fetch origin
$ git reset --hard origin/master
Help, I started my branch from the wrong point
Help I started coding and only realized now that my branch started from the wrong branch! I made some changes that I want to have preserved!
$ git commit -a
// enter useful commit message here
$ git fetch origin
$ git rebase -i origin/master
// remove any commit you do not want by deleting that line
// or you can change pick
to d
or drop
Help, I am messing up my rebase
Help I am in the middle of my rebase, but things are going south! I want to reset to the state before I started to rebase.
$ git rebase --abort
Help, I messed up my rebase
Help I messed up my rebase and want to revert back to the state before the rebase happened! The rebase has concluded.
$ git reflog
// find the line with rebase (start)
// copy the hash
$ git reset --hard #hash#
Help, I see duplicate commits
Help I see duplicate commits and I want them removed! I started the branch from reference X
.
$ git rebase -i x
// change all commits that are duplicated from pick
to fixup
Help, I need to update my branch with master
Help I need to update my branch with master!
$ git fetch origin
$ git rebase origin/master
Help, I need to update my branch with the branch on the repo
Help I need to update my branch with the branch on the repo! My colleague has already made changes and rebased on top of master!
$ git fetch origin
$ git rebase -i origin/master
// remove all commits that do not belong to you in this list
// ideally there should be any, git should be able to resolve
// most duplicate commits
Help, there are a lot of files that should not be committed
Help I see a lot of files that are not part of the repo!
$ git clean -df
// optionally add the files to your .gitignore
Help, I made a lot of changes, but I only want to commit a part of it
Help I made a lot of changes while I was in the flow, but I only want to commit a few changes from this!
$ git commit -p
// mark the changes you want to commit with y
// mark the changes you don't want to commit with n