您的位置:首页 > 其它

Git入门

2015-12-08 14:34 323 查看

1、初识GIT

1.了解系统环境变量

/etc/gitconfig

.gitconfig

 

2.设置身份

git
4000
 config --help  [查看config帮助]

 

git config --global user.name "xdy"  [建一个全局的用户名]

 

git config --global user.email xdy@126.com  [创建邮箱]

 

3.设置编辑器(可选)

$ git config --global core.editor emacs

 

4.设置你的比较工具(可选)

$git config --global merge.tool vimdiff

 

5.检查你的配置(可选)

$ git config --list

 

6.帮助

$git help <verb>

 

$git <verb> --help

 

2、常用命令

2.1、远程下载

mkdir gittest1

 

cd gittest1

 

git init

 

远程下载:git clone git://github.com/git/hello-world.git

 

查看远程仓库的地址:git remote -v

 

2.2、添加文件

cd hello-world

 

echo "hello world" >> helloworld.txt

 

ls *.txt

 

git status[查看状态]

 

git add helloworld.txt 【添加文件】

 

git commit helloworld.txt -m "init helloworld"   [提交并添加日志]

 

2.3、忽略文件

echo "bin" > bin.dll

 

ls bin*

 

echo "bin.dll" > .gitignore

 

cat .gitignore

 

git add .

 

git commit -a -m "submit bin"

 

2.4、查看文件的区别

git diff

git diff --staged     比较workspace VS staged

git diff --cached 比较staged VS local repo

 

2.5、删除文件

git rm bin1.dll  删除文件

删除文件后找回文件办法:

git rm bin1.dll

ls *.dll

git reset HEAD bin1.dll

git checkout -- bin1.dll

ls *.dll

 

删除后提交 git commit -a -m "delete bin1.dll"

 

git log  查看日志

 

git whatchanged 查看发生了哪些改变

 

3、共享及更新项目

git remote 列出远程仓库

git fetch origin(从远程下载,不跟主版本合并,建立一个分支)

 

git pull origin(自动合并)

git push origin master    (master是本地的分)

git branch :列出分支

git format-patch origin/master:打补丁

 

4、分支的管理

git branch 分支名字:建立分支

例如,建立一个名叫xdy的分支,命令为:git branch xdy

git checkout 分支名字:切换到分支上

 

合并merge

git merge “merge branch1 to master” HEAD branch1

 

另一种做法:

git checkout master

git pull .branch1

 

git tag -a Beta1 -m “make beta1” :发布新版本

git tag Beta1:切换回去Beta1

 

5、Git与SVN的对比

5.1、SVN与Git在概念和特性上的区别




 5.2、SVN与Git在操作上的区别



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: