gitee代码管理

gitee代码管理

一、git环境配置

git官方下载网址:Git - Downloading Package

GitHub(世界最主流的远程开源仓库):https://github.com

Gitee(国内目前比较主流的开源仓库):https://gitee.com

GitLab(私有化部署,企业使用较多):https://gitlab.com

二、git工作流程

三、git+PyCharmIDE

PyCharm 配置 Gitee

  • 安装 Gitee 插件:Settings/Preferences → Plungins → Marketplace
  • 配置 Gitee:Settings/Preferences → Version Control → Gitee

img

img

四、git常用命令

image

1. 初始化和配置

# 初始化一个新的 Git 仓库
git init

# 配置全局用户名和邮箱
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

# 查看当前的 Git 配置
git config --list

2. 查看状态和日志

# 查看当前仓库的状态(包括未提交的更改)
git status

# 查看提交历史
git log

# 查看提交历史的简洁版本
git log --oneline

# 查看文件的变更内容
git diff

3. 添加和提交更改

# 将文件添加到暂存区
git add <file>
# 添加所有更改的文件
git add .

# 提交暂存区的更改到仓库
git commit -m "Your commit message"

# 提交所有更改的文件(跳过暂存区)
git commit -am "Your commit message"

4. 分支操作

# 查看所有分支
git branch

# 创建新分支
git branch <branch-name>

# 切换到指定分支
git checkout <branch-name>

# 创建并切换到新分支
git checkout -b <branch-name>

# 删除本地分支
git branch -d <branch-name>

5. 远程仓库操作

# 添加远程仓库
git remote add origin <remote-repo-url>

# 查看远程仓库信息
git remote -v

# 从远程仓库拉取最新代码
git pull origin <branch-name>

# 将本地更改推送到远程仓库
git push origin <branch-name>

# 推送所有分支到远程仓库
git push --all origin

6. 合并和冲突解决

# 合并指定分支到当前分支
git merge <branch-name>

# 查看冲突文件
git status

# 解决冲突后,标记文件为已解决
git add <file>

# 完成合并
git commit

7. 标签操作

# 创建标签
git tag <tag-name>

# 查看所有标签
git tag

# 推送标签到远程仓库
git push origin <tag-name>

8. 撤销更改

# 撤销暂存区的更改
git reset <file>

# 撤销工作区的更改(恢复到最近的提交状态)
git checkout -- <file>

# 回退到指定的提交
git reset --hard <commit-hash>

9. 查看文件历史

# 查看文件的变更历史
git blame <file>

10. 清理和优化

# 清理未跟踪的文件
git clean -fd

# 压缩仓库历史,优化存储
git gc

11. 忽略文件

# 创建或编辑 .gitignore 文件,添加需要忽略的文件或目录
# 例如:
# .idea/
# *.log
# node_modules/

12. 查看远程仓库的钩子信息

# 查看远程仓库的钩子信息(如果支持)
git ls-remote --get-url

13. 设置行结束符

# 设置 Git 自动处理 LF 和 CRLF 行结束符
git config --global core.autocrlf true

14. 查看分支图

# 查看分支的可视化图
git log --graph --oneline --all

15.移除文件

#删除文件
git rm -f <file>`
#移出暂存区保留在本地:
git rm --cached <file>`