From 36b4aadc1115377cf82a9f4ad5177c7aacba4e1c Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Thu, 31 Jul 2014 23:16:43 -0400 Subject: [PATCH 1/2] add 4 tips --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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 +``` + From 9f20e13e414874e19a66719bc2ecce2ab57ef288 Mon Sep 17 00:00:00 2001 From: Jason Moore Date: Thu, 31 Jul 2014 23:21:46 -0400 Subject: [PATCH 2/2] fix prompt to match style guide --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a64e7d0..d299c13 100644 --- a/README.md +++ b/README.md @@ -281,28 +281,28 @@ 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. +(bug24)$ git status +# On branch bug24 +# Your branch is ahead of 'origin/bug24' by 2 commits. # (use "git push" to publish your local commits) # ``` ``` # one commit -git reset --hard HEAD^ +(bug24)$ git reset --hard HEAD^ # two commits -git reset --hard HEAD^^ +(bug24)$ git reset --hard HEAD^^ # four commits -git reset --hard HEAD~4 +(bug24)$ git reset --hard HEAD~4 ``` ## I want to discard my local, uncommitted changes ``` -git reset --hard +(master)$ git reset --hard # or -git checkout -f +(master)$ git checkout -f ``` ## I want to add changes in one file to two different commits @@ -312,6 +312,6 @@ git checkout -f ## I want to remove a file from git but keep the file ``` -git rm --cached log.txt +(master)$ git rm --cached log.txt ```