安装完git 开始配置
安装完 Git 之后,要做的第一件事就是设置你的用户名和邮件地址。 因为每一个 Git 提交都会使用这些信息 配置 win 打开git bash 输入 mac 打开终端
```js
git config --global user.name 你的用户名
git config --global user.email 你的邮箱地址
```
-
配置后,输入 git config —list 查看
-
将来想要修改, 可以重新执行一次配置命令覆盖即可
$ git branch -a
查看分支list
* master
remotes/origin/HEAD -> origin/master
remotes/origin/feature-1962-1
remotes/origin/feature-1982-1
remotes/origin/feature-2050-1
remotes/origin/feature-2201
remotes/origin/feature-2201-2
remotes/origin/feature-2416-1
remotes/origin/feature-2531-1
remotes/origin/feature-烽火
remotes/origin/master
remotes/origin/release
### 使用git branch 分支名称创建本地分支
$ git branch feature-2201-2
### 本地创建后,需要将本地的分支推到远程服务器上,以便其他人都能看到这个分支
$ git push origin feature-2201-2
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered By Gitee.com
To https://git.517la.com/enterprise/CLSettleIntegrateService.git
* [new branch] feature-2201-3 -> feature-2201-3
$ git branch -a
feature-2201-3
* master
remotes/origin/HEAD -> origin/master
remotes/origin/feature-1962-1
remotes/origin/feature-1982-1
remotes/origin/feature-2050-1
remotes/origin/feature-2201
remotes/origin/feature-2201-2
remotes/origin/feature-2201-3
remotes/origin/feature-2416-1
remotes/origin/feature-2531-1
remotes/origin/feature-烽火
remotes/origin/master
remotes/origin/release
###进入.git 所在本地仓库代码目录
$ git checkout origin/feature-2201-2
### 将分支【origin/feature-2201】合并到 /origin/feature-2201-2
$ git merge origin/feature-2201
### 自动合并代码,冲突
Auto-merging src/main/java/com///model/pojo/BaseResponse.java
CONFLICT (content): Merge conflict in src/main/java/com///model/pojo/BaseResponse.java
Automatic merge failed; fix conflicts and then commit the result.
idea 解决冲突 1、右键项目 > 【Git】 > 【Repository】 > 【Merge changes】 2、选择从远程的master合并过来:
3、罗列出冲突的文件列表,没有冲突的文件会自动Commit
4、点击【Merge】进入「Merge Revisions for xxx」窗口解决对应文件的冲突。
在这个窗口,有两个东西需要注意:
A、右上角的「改动点」和「冲突点」
红色行为冲突行;
绿色行为增加的代码行;
灰色行为删除的代码行;
把所有【>>】和【<<】处理完,则会弹出「All changes have been processed」提示:
5、最后提交代码:右键项目 > 【Git】 > 【Commit Directory】
6、最后确认无误,push代码
//解决完成冲突,继续合并命令
git merge origin/feature-2201
//自动合并未产生冲突
git merge origin/feature-2022-zizhen
git status
6、 git push把修改提交到远程仓库 【回滚操作】 退版本(步骤1-6)
1)通过git reset是直接删除指定的commit
1.克隆代码
$git clone xxx.git
2.cd 进入指定分支$ git checkout origin release || git checkout origin/master
3.更新一下代码
\$ git pull
4 得到你需要回退一次提交的commit id
git log
5.回到其中你想要的某个版本 git reset --hard \<commit\_id>
$git reset --hard 897f83a
HEAD is now at 897f83a $ git reset --hard d8528a4737224109fa8cc330bbd0378d3bc89a2f
6. 强制提交一次,之前错误的提交就从远程仓库删除,将当前分支推送到源存储库中的远程引用匹配主机
\$ git push origin HEAD:release --force
注意:将当前分支推送到远程的同名的简单方法,如下 -
\$ git push origin HEAD
示例如下
git 强制更新本地代码
git fetch --all
git reset --hard origin/release
git pull
git 常用命令
git clone https://git.xxx.git
ll
cd CLReportlets/
ll
git add reportlets/
git commit -m 最新报表
git push origin master
合并代码的正确流程