git常用操作

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

  • 使用插件

image-20220709164619567

  • 手写
# 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

image-20220709164341744

add

image-20220709164719331

commit

image-20220709164820965

push

image-20220709165121360

check&reset

image-20220709170137495

merge 分支合并

image-20220709171349862

参考

https://www.bilibili.com/video/BV1vy4y1s7k6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值