diff --git a/README.md b/README.md index 4f9d249..a64e7d0 100644 --- a/README.md +++ b/README.md @@ -274,3 +274,44 @@ And finally, let's cherry-pick the commit for bug #14: ``` (14)$ git cherry-pick 5ea5173 ``` +## I want to discard local commits so my branch is the same as one on the server + +Confirm that you haven't pushed your changes to the server. + +`git status` should show how many commits you are ahead of origin: + +``` +$ git status +# On branch bug123 +# Your branch is ahead of 'origin/bug123' by 2 commits. +# (use "git push" to publish your local commits) +# +``` + +``` +# one commit +git reset --hard HEAD^ +# two commits +git reset --hard HEAD^^ +# four commits +git reset --hard HEAD~4 +``` + +## I want to discard my local, uncommitted changes + +``` +git reset --hard +# or +git checkout -f +``` + +## I want to add changes in one file to two different commits + +`git add` will add the entire file to a commit. `git add -p` will allow to interactively select which changes you want to add. + +## I want to remove a file from git but keep the file + +``` +git rm --cached log.txt +``` +