Git入门指南

第1章        Introduction

1.1   What’s git?

Git is a free & open source, distributed versioncontrol system designed to handle everything from small to very large projectswith speed and efficiency.

Every Git clone is a full-fledged repository withcomplete history and full revision tracking capabilities, not dependent onnetwork access or a central server. Branching and merging are fast and easy todo.

1.2   Download

http://git-scm.com/download

http://code.google.com/p/msysgit/downloads/list?can=3

 

第2章        Usage Guide

2.1   Clone arepository

The best way to get one is by using the git-clone command to download a copy of an existing repository:

git clone git://git.kernel.org/pub/scm/git/git.git

 

2.2   Checkoutfrom branch

git checkout [branchname]

 

2.3   Get up-to-dateresource

git pull

 

2.4   Add fileor directory to repository

$ git add [dir] # include everything in [dir]

$ git add path/to/file

 

2.5   Delete filefrom repository

 

$ git rm path/to/file

 

2.6   Commit torepository

 

$ git commit -m "xxx" [path/to/file | -a]

$ git status

$ git push

 

2.7   Merge

Merge:

$ git checkout $branch2 # To switch branch

$ git merge $branch1

$ git reset --hard HEAD … # To undo the changes,

$ git reset [commit-id] [path/to/file]  # To reset a file back to an old commit

 
Merge conflicts:
 

> git pull           ###failed to pull since merge conflicts

           

> git stash        ###stash away your changes

> git pull          ###  this time, pull will succeedof course

> git stash pop  ### yourchanges are stash back, then Auto merges will happen. And the conflict fileswill be updated by the auto merge, and got 2 persons' changes and marked withhighlights "<<<<", "=====",">>>>".

You must update the files which got conflicts. Files that got"<<<" "===" ">>>" cannot becommit or push.

 

# After your modification to conflicts, you can commit and push now.

> git commit -m "xxx" [file1] [file2] [file3]

> git push

 

2.8   Create atag

$ git tag [tag] 

2.9  Create a branch

$ git branch [branch]

 

2.10Search a string

$ git grep xxx

 

2.11   Undo the last commit 

git reset --hard HEAD~1

 

2.12 List files changed in a commit

git show --name-only $commit

 

2.13   View the change history of a file

git log --follow -p $file

2.14   View a file in a certain commit

git show [commit-id-7char]:[path-of-file] 

 

2.15   Rename or move anelement in Git

git mv [dir1] [dir2]

git mv [file1] [file2]

git mv [dir1]/[file] [dir2]/[file]


 

 

      Written bysmilings in GuangZhou,Apile 1th, 2012

 


你可能感兴趣的:(git,File,download,merge,branch,conflict)