Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### new Git project
- ```
- dev $ mkdir proj && cd proj
- proj $ git init
- Initialized empty Git repository in /home/bosco/dev/proj/.git/
- ```
- #### create and commit a file
- ```
- proj [master] $ touch foo
- proj [master X] $ git add foo && git commit foo -m 'initial commit'
- [master (root-commit) d0d32a9] initial commit
- 1 file changed, 0 insertions(+), 0 deletions(-)
- create mode 100644 foo
- ```
- #### cut a new branch, then change and commit the file
- ```
- proj [master] $ git checkout -b other-branch
- Switched to a new branch 'other-branch'
- proj [other-branch] $ echo change > foo
- proj [other-branch X] $ git commit foo -m 'change foo'
- [other-branch 302476c] change foo
- 1 file changed, 1 insertion(+)
- ```
- #### checkout `master` (now one commit behind `other-branch`)
- ```
- proj [other-branch] $ git checkout master
- Switched to branch 'master'
- ```
- #### change the file to something different from `other-branch` _without_ committing
- ```
- proj [master] $ echo different-change > foo
- ```
- #### attempt to check out `other-branch`
- ```
- proj [master X] $ git checkout other-branch
- error: Your local changes to the following files would be overwritten by checkout:
- foo
- Please, commit your changes or stash them before you can switch branches.
- Aborting
- ```
- #### clear changes, then create a file, and checkout `other-branch`
- ```
- proj [master X] 做 git checkout -- foo
- proj [master] 做 touch bar
- proj [master X] 做 git status -s
- ?? bar
- proj [master X] 做 git checkout other-branch
- Switched to branch 'other-branch'
- proj [other-branch X] 做 git status -s
- ?? bar
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement