GIT基本操作

作者:Garany 发布于:2017-08-07 分类:破万卷书
git同时提供SSH和HTTPS链接。只有当你拥有仓库的写权限时,才可以使用 SSH。

1.全局配置用户名,邮箱
$ git config --global user.name "gitlab's Name"  
$ git config --global user.email "gitlab@xx.com"
$ git config --list

2.在项目根目录下进行单独配置
$ cd Project_name
$ git config user.name "gitlab's Name" 
$ git config user.email "gitlab@xx.com" 
$ git config --list

一、克隆已经存在的仓库
$ git clone  git@GW:user1/Project_1.git
$ git clone  git@GW:user1/Project_2.git Ject_A #克隆仓库,并命名为Ject_1

二、新建项目,创建说明文档,提交
$ mkdir ject1
$ cd ject1
$ git init # 初始化工作区
$ git remote add origin git@GW:user1/Project_3.git # 添加远程服务器
$ touch README.md #添加说明文档
$ git status # 查看状态
$ git add README.md # 加入文件到提交任务
$ git status
$ git commit -m 'add README.md' # 完成一次提交
$ git push origin master # 推送改动到指定的远程服务器

三、新建文件,修改文件,提交
$ echo abcdef>123
$ echo 'This`s local ject1' > README.md
$ git status
$ git add --all # 加入全部修改到提交任务
$ git status
$ git commit -am 'edit all' #提交全部修改
$ git push origin master

三、删除文件,提交
$ rm -rf 123
$ git status
$ git rm 123
$ git status
$ git commit -m 'delete 123'
$ git push origin master

# 查看项目并更新本地代码更新
$ cd project
$ git pull
$ git branch –set-upstream-to=origin/<branch> master
# 查看状态
$ git status
未跟踪文件Untracked:仓库里新建了一个文件,但是没有把文件加入到 Git 的管理之中。
已跟踪文件Tracked:已经加入到 Git 管理的文件。
暂存区文件Staged:被修改了的已跟踪文件,并加入到 Git 的提交队列中。

# 撤销提交任务
$ git reset filename
# 查找提交的引用指针:
$ git log --oneline

四、版本回退
正常提交
# vim $file
# git add $file
# git commit -m 'INFO' $file
1.编辑文件后回退
# vim $file
# git checkout $file
2.编辑文件并add后回退
# vim $file
# git add $file
# git reset HEAD $file
# git checkout $file 
3.编辑文件、add并commit后回退
# vim $file
# git add $file
# git commit -m 'INFO' $file
# git log $file
# git reset --hard $commit_ID
标签: linux 服务器 Git

我来说说