add 4 tips

This commit is contained in:
Jason Moore 2014-07-31 23:16:43 -04:00
parent 9536d6987d
commit 36b4aadc11
1 changed files with 41 additions and 0 deletions

View File

@ -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
```