git 常用命令

http://gitref.cyj.me/zh/index.html

http://gitbook.liuhui998.com/index.html


使用 git add 添加需要追踪的新文件和待提交的更改, 然后使用 git status 和 git diff 查看有何改动, 最后用 git commit 将你的快照记录。这就是你要用的基本流程,绝大部分时候都是这样的。


git init -- 建立仓库


git add <file> = git commit -a -- 添加文件到缓存


git commit -m(注释) --allow-empty -- 记录缓存内容的快照

commit之后才算正式有了分支

提交前需要输入用户名,邮箱

git config --global user.name 'Your Name'

git config --global user.email [email protected]


git remote add [alias] [url] -- 添加一个新的远端仓库


git push [alias] [branch]-- 将本地commit的代码更新到远程版本库中


git pull [alias] [branch] -- 从远端仓库提取数据并尝试合并到当前分支

产生冲突时,<<<<<<< Head和========之间的部分是本次要提交的,=======和>>>>>>>是服务器上现在的


HelloGIT at client
<<<<<<< HEAD
Update readme file at local and submit to test reslove the confict.
hubert
=======
Update readme file at local and submit to test reslove the confict
testsdfsdfsdfsdfsdfsd
>>>>>>> 239b3c2cedd978fdd9f567ce6920fc17e7110daa


git status -s(简短模式)  --  查看文件在工作目录与缓存的状态



git branch (branchname) 创建新分支

git checkout -b (branchname) 创建新分支,并立即切换到它

git branch -d (branchname) 删除分支


git checkout切换到新的分支上下文


git merge将分支合并到你的当前分支

撤销合并: $ git reset --hard HEAD


git log显示一个分支中提交的更改记录


git tag给历史记录中的某个重要的一点打上标签


$ git log -p

查看日志

$ git log --stat

如果用--stat选项使用'git log',它会显示在每个提交(commit)中哪些文件被修改了, 这些文件分别添加或删除了多少行内容.

$ git log --pretty=short
$ git log --pretty=short

格式化日志


stash

先将未提交的修改暂存起来,接着清除所有改动,使之与没修改时一样。

若你正在开发功能 A,又需立即去开发功能 B。A 的代码正改到一半,未认真整理,你不想立即提交。此时……请呼叫 stash ~。

它会使你所有未提交的修改瞬间不见了:
$ git stash
它会使刚刚不见了的修改,瞬间又回来了:
$ git stash pop


你可能感兴趣的:(Web,命令,git)