Git常用命令

Create remote repo

pwd:/Users/zhanglx/workspace/gittest/
git init --bare --shared

Clone repo from remote repo

git clone /Users/zhanglx/workspace/gittest/

Init a local git repo and add a remote

This is equal to "Clone"

mkdir myrepo
cd myrepo/
git init
git remote add origin /Users/zhanglx/workspace/gittest/

New branch and switch to this branch

git branch test
git checkout test

Type git branch to check which branch you are working on.

Add, modify, commit, reset and checkout history

Git文件状态

Git文件的状态分为untracked和tracked, untracked文件是指新建的文件,尚未被git管理起来。

tracked又分为三种状态:

已提交(committed),已修改(modified)和已暂存(staged)。已提交表示文件已被安全地保存在本地数据库中了;已修改表示修改了某个文件,但没有提交保存;已暂存表示把已修改的文件放在下次提交时要保存的清单中。

Github

git remote -v or git remote show origin 查看相关信息 git push origin master 将commit的代码,push到github上。 git pull origin master 将github上的代码,update到本地。

Delete

git delete file 然后commit的,将无法恢复。 rm file, 可以通过git checkout -- file进行恢复。 git rm --cached file,只是在缓存中删除,

恢复更改的文件 git checkout — //未git add的文件

git reset HEAD //已经git add的文件,可以用这个取消add,然后用上一条命令恢复

Push master branch of locale repo to remote origin

git push origin master

Pull (if there are some conflicts, git will call git merge automatically)

git pull origin master

创建SSH key

ssh-keygen
生成的SSH key文件保存在中~/.ssh/id_rsa.pub

添加SSH key到github

接着拷贝.ssh/id_rsa.pub文件内的所以内容
打开github帐号管理中的添加SSH key界面的步骤如下:
1. 登录github
2. 点击右上方的Accounting settings图标
3. 选择 SSH key
4. 点击 Add SSH key

TAG
$ git tag v1.4 -m ‘version 1.4′
$ git tag
$ git show v1.4

$git checkout tag_name    //在当前分支上 取出 tag_name 的版本
$git checkout -b branch_name tag_name //从 tag 创建一个分支,然后就和普通的 git 操作一样了
posted @ 2015-03-06 08:49  LessIsMorer  阅读(262)  评论(0编辑  收藏  举报