Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #### new Git project
  2.  
  3. ```
  4. dev $ mkdir proj && cd proj
  5.  
  6. proj $ git init
  7. Initialized empty Git repository in /home/bosco/dev/proj/.git/
  8. ```
  9.  
  10. #### create and commit a file
  11.  
  12. ```
  13. proj [master] $ touch foo
  14.  
  15. proj [master X] $ git add foo && git commit foo -m 'initial commit'
  16. [master (root-commit) d0d32a9] initial commit
  17. 1 file changed, 0 insertions(+), 0 deletions(-)
  18. create mode 100644 foo
  19. ```
  20.  
  21. #### cut a new branch, then change and commit the file
  22.  
  23. ```
  24. proj [master] $ git checkout -b other-branch
  25. Switched to a new branch 'other-branch'
  26.  
  27. proj [other-branch] $ echo change > foo
  28.  
  29. proj [other-branch X] $ git commit foo -m 'change foo'
  30. [other-branch 302476c] change foo
  31. 1 file changed, 1 insertion(+)
  32. ```
  33.  
  34. #### checkout `master` (now one commit behind `other-branch`)
  35.  
  36. ```
  37. proj [other-branch] $ git checkout master
  38. Switched to branch 'master'
  39. ```
  40.  
  41. #### change the file to something different from `other-branch` _without_ committing
  42.  
  43. ```
  44. proj [master] $ echo different-change > foo
  45. ```
  46.  
  47.  
  48. #### attempt to check out `other-branch`
  49.  
  50. ```
  51. proj [master X] $ git checkout other-branch
  52. error: Your local changes to the following files would be overwritten by checkout:
  53. foo
  54. Please, commit your changes or stash them before you can switch branches.
  55. Aborting
  56. ```
  57.  
  58. #### clear changes, then create a file, and checkout `other-branch`
  59.  
  60. ```
  61. proj [master X] 做 git checkout -- foo
  62.  
  63. proj [master] 做 touch bar
  64.  
  65. proj [master X] 做 git status -s
  66. ?? bar
  67.  
  68. proj [master X] 做 git checkout other-branch
  69.  
  70. Switched to branch 'other-branch'
  71. proj [other-branch X] 做 git status -s
  72. ?? bar
  73. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement