git常用操作
git客户端操作
clone 克隆
# clone 克隆代码
git clone https://gitee.com/darkfox888/git-study.git
init 生成git仓库
# 生成git仓库
git init
add 操作本地暂存区
# 查看所有文件
$ ll -a
total 9
drwxr-xr-x 1 197121 0 Jul 9 11:15 ./
drwxr-xr-x 1 197121 0 Jul 9 11:10 ../
drwxr-xr-x 1 197121 0 Jul 9 11:16 .git/
-rw-r--r-- 1 197121 102 Jul 9 11:15 hello.git
# 添加到暂存区
$ git add hello.git
warning: LF will be replaced by CRLF in hello.git.
The file will have its original line endings in your working directory
# 查看git状态
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello.git
# 从暂存区删除
$ git rm --cached hello.git
# 查看git状态
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
hello.git
nothing added to commit but untracked files present (use "git add" to track)
commit 提交本地库
$ git commit -m "first commit"
[master (root-commit) 72f477a] first commit
1 file changed, 6 insertions(+)
create mode 100644 hello.git
$ git status
On branch master
nothing to commit, working tree clean
reset 版本穿梭
# 查看历史版本
$ git reflog
d4b7129 (HEAD -> master) HEAD@{0}: commit: third commit
72f477a HEAD@{1}: commit (initial): first commit
@DESKTOP-OFL64OM MINGW64 /d/work/coding/IDEA/workspace/gitStudy (master)
# 版本穿梭
$ git reset --hard 72f477a
HEAD is now at 72f477a first commit
@DESKTOP-OFL64OM MINGW64 /d/work/coding/IDEA/workspace/gitStudy (master)
# 查看历史版本
$ git reflog
72f477a (HEAD -> master) HEAD@{0}: reset: moving to 72f477a
d4b7129 HEAD@{1}: commit: third commit
72f477a (HEAD -> master) HEAD@{2}: commit (initial): first commit
branch 分支操作
基本操作
#查看当前分支
$ git branch -v
* master 72f477a first commit
#创建分支
$ git branch temp01
@DESKTOP-OFL64OM MINGW64 /d/work/coding/IDEA/workspace/gitStudy (master)
#查看当前分支
$ git branch -v
* master 72f477a first commit
temp01 72f477a first commit
@DESKTOP-OFL64OM MINGW64 /d/work/coding/IDEA/workspace/gitStudy (master)
# 切换分支
$ git checkout temp01
Switched to branch 'temp01'
分支合并
- 正常合并
$ git merge temp01
Updating 72f477a..487cfbb
Fast-forward
hello.git | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
- 冲突合并需要手动修改后,再次提交
push 提交代码
#提交
git push https://gitee.com/darkfox888/git-study master
pull 拉取代码
#拉取
git pull https://gitee.com/darkfox888/git-study master
IDEA集成Git
忽略文件 git.ignore
- 使用插件
- 手写
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
hs_err_pid*
.classpath
.project
.settings
target
.idea
*.iml
git init
add
commit
push
check&reset
merge 分支合并
参考
https://www.bilibili.com/video/BV1vy4y1s7k6