git的使用和基本命令

创建一个新仓库,在本地控制台上传这些命令

1
2
3
4
5
6
git init
git add .
git commit -m "注释"
git branch -M main
git remote add origin (https://github.com/zwxl/Javaswing-LibrarySystem.git)远程仓库链接
git push -u origin main

在一个已有的仓库上,上传命令

1
2
3
git remote add origin (https://github.com/zwxl/Javaswing-LibrarySystem.git)远程仓库链接
git branch -M main
git push -u origin main

新建分支

1
2
3
4
5
git branch name
git checkout name
git add .
git commit -m "注释"
git push -u origin name

上传错误

1
error: remote origin already exists.

解决方法:

​ git remote -v:查看远程仓库

此时已经关联了仓库,把关联的这个仓库删掉,

​ git remote rm origin (删除已关联仓库)

git命令

基本指令

  • git init :用来初始化一个git仓库。
  • git add: 添加文件到本地缓存(暂存区)。(git add . 是将该目录下的所有文件加入缓存区; git add *.java: 选择后缀文件添加)
  • git commit: 将暂存区内容添加到本地仓库中。
  • git config:提交代码到远程仓库配置用户名和密码。

git config —global user.name ‘你的用户名’

git config —global user.email ‘你的邮箱’

  • git clone:远程克隆一个仓库。
  • git rm:删除命令。

Git的分支管理

  • git branch:查看分支命令。
  • git branch 分支名字:创建分支命令。
  • git checkout 分支名字:切换分支命令。
  • git merge:合并分支。
  • git branch -d (分支名字):删除分支命令

Git 远程仓库

  • git remote add:Git 远程仓库。
  • git remote:查看当前的远程仓库。
  • git push:推送到远程仓库。
  • git remote rm:删除远程仓库。
  • git pull:拉取远程仓库文件(前提是文件中有.git)

git实现版本回归

1
2
3
4
5
6
commit (4574c243631961ee0e44c51bdb63def3a6957d66) 版本号(HEAD -> main, origin/main)
Author: 3036354190 <3036354190@qq.com>
Date: Fri Jun 2 10:36:40 2023 +0800

Java开发的秒杀系统

git log: 查看日志

git reset — hard 版本号: 跳转版本号。