git 使用

一、创建新分支

1. git branch 查看已有的所有分支。

2. git branch andy 创建名叫andy的分支。

3. git branch  再看看是不是多了一个叫andy的分支,例如:

  *master

    andy

4. git checkout andy 切换到andy分支

5. git push --set-upstream origin andy  将andy分支推送到远程仓库

6. git checkout master 切换回mster主分支。

二、删除分支

1. git push origin --delete andy  把远程的andy分支删除掉

2. git branch -d andy  同时把本地对应的andy分支删掉 

三、clone 分支

git clone 下来的仓库是没有其分支的,怎么办?如下:

1. git branch -a,列出所有分支名称如下:
  remotes/origin/andy
  remotes/origin/master
2. git checkout -b andy origin/andy,作用是checkout远程的andy分支,在本地起名为andy分支,并切换到本地的andy分支

3. git branch 看看就有了。

 四、回退指定版本

A. 回滚指定文件

1. git reset e5ca2e9a74634b744b19ed05252ccb49092bff8e ./Elasticsearch.php

2. git commit -m"reset"

3. git checkout ./Elasticsearch.php

4. git push

完成

B. 回滚整个项目

1. git reset --hard e5ca2e9a74634b744b19ed05252ccb49092bff8e

五、Git 多平台换行符问题(LF or CRLF)

如果涉及到在多个系统平台上工作,推荐将 git 做如下配置:

git config --global core.autocrlf input
git config --global core.safecrlf true

http://kuanghy.github.io/2017/03/19/git-lf-or-crlf

原文地址:https://www.cnblogs.com/bootoo/p/5131734.html