首先下载安装git,完成后打开git bash,能够先输入:git help 简单了解一下有哪些命令.....html
一、配置git,在git bash窗口中输入下面两行命令:git
git config --global user.name "user_name"github
git config --global uer.email "name@example.com"windows
红色文字部分根据我的信息修改(下同)ruby
--global参数表示当前计算机上将要建立的全部仓库都使用这个配置。bash
二、建立路径:mkdir dir_nameapp
三、跳转到制定目录:cd dir_namefetch
四、显示当前工做路径: pwdui
五、将当前目录变成git能够管理的仓库:git initspa
六、添加并提交修改:
git add file_name
git commit -m "added a file"
七、查看状态:git status
八、查看修改先后的变化:git diff
九、查看提交记录:
git log
让结果只显示一行的命令
git log --pretty=oneline
或者先配置
git config format.pretty oneline
另查看分支图:
git log --graph
十、回到过去:
退回上一版本:git reset --hard head^
退回上上一版本:git reset --hard head^^
退回上...(N个)一版本:git reset --hard head~N
十一、回到过去或将来:
(1)获取历次commit 的 id 号:git reflog
(2)git reset --hard commit_id
十二、撤销指定文件的修改(包括删除):
(1)撤销在工做区的修改(即让文件回到最近一次git commit
或git add
时的状态):git checkout -- filename
其中 -- 表示在当前分支下,而不是转换到新的分支
(2)撤销在暂存区及工做区的修改(即让文件回到最近一次git commit时的状态):git reset head filename
1三、与本地仓库与GitHub 仓库的关联:
一个简单的方法:在GitHub上建立新的仓库后,会跳转到对应的仓库。咱们根据 Quick setup 的提示进行操做便可,即将对应的命令行复制、粘贴到git bash窗口上
1四、branch的操做:
(1)建立并跳转到新的branch:
git checkout -b branch_name
至关于:
git branch branch_name
git checkout branch_name
(2)跳转到指定branch (包括master):
git checkout branch_name
(3)将分支推送到远程仓库:
git push origin branch_name
(4)删除branch:
已合并分支删除:git branch -d branch_name 或 git checkout -d branch_name
未合并分支删除:git branch -D branch_name 或 git checkout -D branch_name
(5)查看全部分支:
git branch
1五、更新本地仓库至最新改动:
git pull
1六、合并制定分支到当前分支:
git merge branch_name
加上 --no-ff 参数表示禁用Fast forward,能够保留分支历史:
git merge --no-ff branch_name
若出现冲突,则须要修改文件而后再合并;改完以后执行:
git add file_name
合并前可先检查分支的差别:
git diff source_branch target_branch
1七、获取远程仓库的最新版本并覆盖本地版本:
git fetch origin
并将本地主分支指向它:
git reset --hard origin/master
1八、标签操做:
(1)建立标签:git tag v1.0 commit_id
(2)显示指定标签版本:git show tag_name
1九、打开图形化git:
gitk
20、工做现场的操做:
(1)保存工做现场:git stash
(2)查看:git stash list
(3)恢复: git stash apply
(4)删除:git stash drop
(5)恢复并删除:git stash pop
本文地址:http://www.cnblogs.com/laishenghao/p/5500835.html
做者博客:( •̀ ω •́ )y