我是靠谱客的博主 发嗲香烟,最近开发中收集的这篇文章主要介绍IntelliJ IDEA With Git环境准备IntelliJ IDEA With Git 开发过程Git 相关参考,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
记录下Git如何与IntelliJ IDEA协作
文章目录
- 环境准备
- IntelliJ IDEA With Git 开发过程
- 1. 初次获取远端代码
- 2. 查看远端仓库分支
- 3. 将指定的远端分支同步到本地(建议同远端名一致)
- 4. 查看本地当前所在分支 & 关联的远端分支
- 5. 准备在指定分支开发
- 6. coding & show diff
- 7. 将文件添加到暂存区 & 提交工作分支的修改 | 更改提交的comments
- 8. 撤销本地的修改
- 9. 切换到与远端同步的主分支 & 同步可能的远端修改
- 10. 切换到工作分支 & rebase | resoleve conflicts
- 11. 切换到主分支 & 合并修改到主分支
- 12.本地分支同步到远端分支(会改变远程分支的文件)
- Git 相关
- 回退到分支指定版本
- Cherry-Pick
- 本地分支重命名
- 本地新建分支推送到远端
- 删除本地分支 & 删除远端分支
- 查看版本变动
- 参考
环境准备
- Git下载
- IntelliJ IDEA下载
- IntelliJ IDEA 的 License server 可以使用:
http://8lovelife.com:1017
IntelliJ IDEA With Git 开发过程
1. 初次获取远端代码
- 使用IntelliJ IDEA Terminal
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2uotZYcM-1675266252937)( https://8lovelife-1256398294.cos.ap-shanghai.myqcloud.com/Intellij%20Idea/IdeTerminal.png)]
Mac:code mac$ git clone https://github.com/grpc/grpc-java.git
Cloning into 'grpc-java'...
2. 查看远端仓库分支
Mac:dmz-inward- mac$ git branch -av
* master 0388b70 some feture
remotes/origin/HEAD -> origin/master
remotes/origin/feature cd52891 some features
remotes/origin/master 0388b70 some feture
3. 将指定的远端分支同步到本地(建议同远端名一致)
Mac:dmz-inward- mac$ git checkout -b feature origin/feature
Branch 'feature' set up to track remote branch 'feature' from 'origin'.
Switched to a new branch 'feature'
4. 查看本地当前所在分支 & 关联的远端分支
Mac:dmz-inward- mac$ git branch // 查看当前分支
* feature
master
Mac:dmz-inward- mac$ git branch -avv // 查看当前分支关联的远端分支
* feature bb87089 [origin/feature] Merge branch 'feature_test' into feature
feature_test dd90129 //
master 0388b70 [origin/master] some feture
remotes/origin/HEAD -> origin/master
remotes/origin/feature bb87089 Merge branch 'feature_test' into feature
remotes/origin/master 0388b70 some feture
- View 确认
5. 准备在指定分支开发
Mac:dmz-inward- mac$ git checkout -b feature_test
Switched to a new branch 'feature_test'
6. coding & show diff
- coding
- 随时查看本地的变动,防止遗漏:
7. 将文件添加到暂存区 & 提交工作分支的修改 | 更改提交的comments
Mac:dmz-inward- mac$ git add . // 添加暂存区
Mac:dmz-inward- mac$ git commit -m "feature add test" // 提交
[feature_test 7590940] feature add test
2 files changed, 7 insertions(+)
create mode 100644 dmz-inward-test/src/test/java/Test.java
Mac:dmz-inward- mac$ git commit --amend // 修改提交的comments
[feature_test 90b9e43] feature add retests
Date: Mon May 21 10:40:06 2018 +0800
2 files changed, 7 insertions(+)
create mode 100644 dmz-inward-test/src/test/java/Test.java
- 暂存区与HEAD
8. 撤销本地的修改
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KZkboOe4-1675266252938)( https://8lovelife-1256398294.cos.ap-shanghai.myqcloud.com/Intellij%20Idea/revert.png)]
9. 切换到与远端同步的主分支 & 同步可能的远端修改
Mac:dmz-inward- mac$ git checkout feature // 切换分支
Switched to branch 'feature'
Your branch is up to date with 'origin/feature'.
Mac:dmz-inward- mac$ git pull // 同步远端可能的修改
Already up to date.
10. 切换到工作分支 & rebase | resoleve conflicts
Mac:dmz-inward- mac$ git checkout feature_test
Switched to branch 'feature_test'
Mac:dmz-inward- mac$ git rebase feature
Current branch feature_test is up to date.
若rebase遇到冲突则手动解决,利用Intelli Idea 的show diff 可以清晰观察冲突点
冲突解决后进行:
git add *
git rebase --continue
11. 切换到主分支 & 合并修改到主分支
Mac:dmz-inward- mac$ git checkout feature
Switched to branch 'feature'
Your branch is up to date with 'origin/feature'.
Mac:dmz-inward- mac$ git merge --no-ff feature_test
Merge made by the 'recursive' strategy.
dmz-inward-test/src/test/java/Test.java | 6 ++++++
dmz-inward-test/src/test/java/TestFast.java | 1 +
2 files changed, 7 insertions(+)
create mode 100644 dmz-inward-test/src/test/java/Test.java
- 分支
12.本地分支同步到远端分支(会改变远程分支的文件)
Mac:dmz-inward- mac$ git push
Counting objects: 17, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (17/17), done.
Writing objects: 100% (17/17), 1.36 KiB | 698.00 KiB/s, done.
Total 17 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), completed with 4 local objects.
Git 相关
Git 常用的操作命令
回退到分支指定版本
- 查看分支历史变动历史,回退指定版本号
Mac:dmz-inward- mac$ git reset --hard bb8708981a01eb568d114ed7ddad71f6cd881f7e
HEAD is now at bb87089 Merge branch 'feature_test' into feature
Cherry-Pick
将某一分支的commit修改,应用到当前本地分支。如:将feature上的某一commit修改应用到master上
Mac:dmz-inward- mac$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
- Cherry-Pick
- Intellij Idea With Git 开发过程
本地分支重命名
Mac:dmz-inward- mac$ git branch -m feature feature_rename
本地新建分支推送到远端
Mac:dmz-inward- mac$ git push --set-upstream origin feature_one
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/dreamming/dmz-inward-.git
* [new branch] feature_one -> feature_one
Branch 'feature_one' set up to track remote branch 'feature_one' from 'origin'.
删除本地分支 & 删除远端分支
Mac:dmz-inward- mac$ git branch -d feature_one // 删除本地分支
warning: deleting branch 'feature_one' that has been merged to
'refs/remotes/origin/feature_one', but not yet merged to HEAD.
Deleted branch feature_one (was dd90129).
Mac:dmz-inward- mac$ git push origin :feature_one // 删除远端分支
To https://github.com/dreamming/dmz-inward-.git
- [deleted] feature_one
查看版本变动
- 查看分支历史变动
Mac:dmz-inward- mac$ git reflog
47128b4 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: commit: //
0388b70 HEAD@{1}: checkout: moving from feature to master
bb87089 (feature_two, feature) HEAD@{2}: checkout: moving from master to feature
0388b70 HEAD@{3}: checkout: moving from feature to master
bb87089 (feature_two, feature) HEAD@{4}: reset: moving to bb8708981a01eb568d114ed7ddad71f6cd881f7e
06d0579 (origin/feature) HEAD@{5}: commit: __
bb87089 (feature_two, feature) HEAD@{6}: checkout: moving from master to feature
0388b70 HEAD@{7}: checkout: moving from feature_one to master
- 查看文件更改人
参考
我的博客
最后
以上就是发嗲香烟为你收集整理的IntelliJ IDEA With Git环境准备IntelliJ IDEA With Git 开发过程Git 相关参考的全部内容,希望文章能够帮你解决IntelliJ IDEA With Git环境准备IntelliJ IDEA With Git 开发过程Git 相关参考所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复