git一些初级指令

来源:互联网 发布:weka算法介绍 编辑:程序博客网 时间:2024/06/02 16:50
git版本控制之道   使用git的一些指令




//输入git help查看所有的命令


git help
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <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 integrate with another repository or a local bra
   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


//设置提交者信息
1.git config --global user.name "linxiaobai"
 git config --global user.email "lin_music@126.com"


可以用 git config --global --list来查看以上信息是否设置成功,如果直接用github客户端打开过来的,上诉设置应该不用进行


2.git config --global color.ui "auto" 设置使用不同的颜色显示不同类型的内容


3.将powershell的当前目录调至某一个目录下(例如G盘下的gittest文件夹)里面 然后mkdir test新建一个文件夹
cd test 进入 


4.随时查看当前路径可以输入 pwd 指令


5.输入git init创建版本库


6.New-Item 简写 ni hello.php        type输入 file 即文件


7. notepad hello.php 对hello.php进行编辑
<?php
$str = "hello php";
var_dump($str);
?>
编辑完成后strl+s保存,然后alt+F4退出编辑






8.git add hellp.php 将文件添加到版本库的索引


9.git status查看当前文件的状态,看到显示Initial commit 初始化提交,即git add后进入的是预提交的状态


10.git commit -m "add a hello.php"  //-m后面跟的是类似说明的文字


直接写git commit 不加后面会弹出一个notepad编辑,然后在里面输入效果和 -m后输入是一样的


提交后再输入git status可以发现已经没有要提交的内容了,说明刚才的文件提交成功




11.熟练使用一下以上命令,新建一个TT.java,然后什么都不写,直接add加commit,然后修改TT.java为它增加HelloWorld内容
然后输入git status查看状态,发现提示你修改过了文件但是没有提交,这时候直接git commit -a提交,不用预提交


12.接下来创建一个分支再在分支上建一个Hello.c后合并分支


1) git branch RB_1.0 master
2)  git checkout RB_1.0 //发现powershell里面的前面高亮区域从master变为RB_1.0
3) 建立Hello.c并提交和上面类似
处理发布
4)git tag 1.0 RB_1.0
5) git tag      //查看刚才打过的标签
6)git checkout master  切换回去主分支
7)git rebase RB_1.0
8) git branch -d RB_1.0  删除分支
如何给1.0.x分支打补丁
9)git branch RB_1.0.1 1.0
/*
G:\git\mygithub\test2 [master]> git branch RB_1.0.1 RB_1.0      
fatal: Not a valid object name: 'RB_1.0'.     
G:\git\mygithub\test2 [master]> git branch RB_1.0.1 1.0
*/
给代码发布创建归档微距,没有必要总是把历史记录一起发布,通常情况下,把标签对应的版本内容打包成一个tar或是zip包

10)git archive --format=tar\--prefix=test2-1.0/1.0\>test2-1.0.zip     //有点小问题,不知道什么原因




同步到GitHub
/*以下方式同步到GitHub发现不行*/
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/linxiaobai/bb.git
git push -u origin master




先在GitHub上面建一个版本库,然后用以下命名克隆到本地
git clone  https://github.com/linxiaobai/bb.git bb-remote




cd bb-remote 
然后各种修改后commit后,用git push就可以上传到GitHub上了


发现一个非常不错的git教程   http://www.ihref.com/read-16369.html   看这个吧,进阶一下~

0 0
原创粉丝点击