Git使用

1,718 views

Published on

GIT使用简介

Published in: Technology, Business
  • Be the first to comment

Git使用

  1. 1. git davidx <mykingheaven@gmail.com>
  2. 2. git • SCM • • •
  3. 3. svn 较
  4. 4. GIT
  5. 5. 仓库 davidx-laptop:Projects davidx$ mkdir test davidx-laptop:Projects davidx$ cd test davidx-laptop:test davidx$ git init Initialized empty Git repository in /Users/davidx/Projects/test/.git/ davidx-laptop:test davidx$
  6. 6. 进 仓库 davidx-laptop:test davidx$ touch README davidx-laptop:test davidx$ git add README davidx-laptop:test davidx$ git add test2/ davidx-laptop:test davidx$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README # new file: test2/file1 # new file: test2/file2 # new file: test2/file3
  7. 7. davidx-laptop:test davidx$ git commit -m "init commit" [master (root-commit) e55ac19] init commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README create mode 100644 test2/file1 create mode 100644 test2/file2 create mode 100644 test2/file3
  8. 8. 历 davidx-laptop:test davidx$ git log commit e55ac19e882cc3c931f2d844df14578c8109af8e Author: davidx <mykingheaven@gmail.com> Date: Tue Sep 21 15:35:59 2010 +0800 init commit
  9. 9. 删 davidx-laptop:test davidx$ git rm test2/file1 rm 'test2/file1' davidx-laptop:test davidx$ git rm test2/file2 test2/file3 rm 'test2/file2' rm 'test2/file3' davidx-laptop:test davidx$ git commit -m "delete some files" [master 458781d] delete some files 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test2/file1 delete mode 100644 test2/file2 delete mode 100644 test2/file3
  10. 10. 销 davidx-laptop:test davidx$ git checkout README
  11. 11. • git reset SHA1 • git reset HEAD~1
  12. 12. clone • git clone <git_url> <local_directory>
  13. 13. davidx-laptop:test davidx$ git usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS] The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG See 'git help COMMAND' for more information on a specific command.
  14. 14. git 级
  15. 15. • push • pull
  16. 16. branch • GIT • 应该 • 结 , 应该merge
  17. 17. branch • : git branch <branch name> • 换 : git checkout <branch name> • -- 换 该 : git checkout -b <branch name>
  18. 18. branch davidx-laptop:test davidx$ git branch new davidx-laptop:test davidx$ git checkout new Switched to branch 'new' davidx-laptop:test davidx$ git branch master * new davidx-laptop:test davidx$ git checkout -b new2 Switched to a new branch 'new2' davidx-laptop:test davidx$ git branch master new * new2
  19. 19. branch • : git branch • 删 : git branch -d <branch name> • master • 删
  20. 20. branch • : git merge <source branch name> • 标 为
  21. 21. branch davidx-laptop:test davidx$ git checkout new2 Switched to branch 'new2' davidx-laptop:test davidx$ touch new_file_2 davidx-laptop:test davidx$ git add new_file_2 davidx-laptop:test davidx$ git commit -a [new2 e69c6a9] new file: new_file_2 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 new_file_2 davidx-laptop:test davidx$ git checkout master Switched to branch 'master' davidx-laptop:test davidx$ git merge new2 Updating cb88fd0..e69c6a9 Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 new_file_2
  22. 22. tag • 态 标 • branch • 为version发
  23. 23. tag davidx-laptop:test davidx$ git tag davidx-laptop:test davidx$ git tag 1.0 davidx-laptop:test davidx$ git tag 1.0
  24. 24. 问题
  25. 25. 问题 Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com If the identity used for this commit is wrong, you can fix it with: git commit --amend --author='Your Name <you@example.com>'
  26. 26. GITCONFIG • ~/.gitconfig • [user] section • name=XXXX • email=XXXX@YYY.ZZZ
  27. 27. GITCONFIG [user] name = davidx email = mykingheaven@gmail.com [core] editor = vim

×