git 命令行基本操作

来源:互联网 发布:ios良心网游 知乎 编辑:程序博客网 时间:2024/06/05 03:07

学习网站  http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

git命令中最基本使用的

1、从远程仓库克隆项目

git clone 远程仓库地址 

git clone https://git.oschina.net/huanghehg/testgit.git
Cloning into 'testgit'...
Username for 'https://git.oschina.net':用户名

Password for 'https://huanghehg@git.oschina.net':密码(此处不会显示)
remote: Counting objects: 23, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 23 (delta 7), reused 0 (delta 0)
Unpacking objects: 100% (23/23), done.
Checking connectivity... done.


2、查看本地文件状态

git status

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:(会提示该怎么做)
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)


        modified:   git.txt


no changes added to commit (use "git add" and/or "git commit -a")

3、将修改内容提交至暂存区

git add 修改文件

$ git add git.txt
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
        modified:   git.txt

4、将暂存区内容提交本地版本库

git commit -m '填写备注'

$ git commit -m 'testgit'
[master 6be6977] testgit
 1 file changed, 2 insertions(+), 1 deletion(-)

5、因为大部分情况是多人协作开发,所以在把本地版本库推送至远程仓库之前需要拉取最新代码

git pull origin 分支名称

From https://git.oschina.net/huanghehg/testgit
 * branch            master     -> FETCH_HEAD
Already up-to-date.

6、如果发生冲突解决冲突之后走这步

git push origin 分支名称

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 253 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://git.oschina.net/huanghehg/testgit.git
   31af53a..6be6977  master -> master

7、开辟分支

git checkout -b 分支名字

开辟新分支 并跳转到新分支

8、切换分支

git checkout 分支名字

9、查看本地分支列表

git branch

$ git branch
  master
* testbranch1(*代表当前分支)

10、合并分支

git merge 分支名字

11、查看log

git log

12、版本回滚

git reset --hard 版本号

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000

0 0