Git详细使用流程

初始化git仓库

git init

执行命令后文件夹下将会在执行命令路径下生成.git隐藏文件
上传该路径下的所有内容到暂存区

git add .

通常项目中都有read.me,创建read.me文件
将read.me添加到git仓的暂存区

git add read.me

查看代码改动

git status

使用git status后,命令行显示信息如下

On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: read.me

提交代码

git commit -m "备注信息"

提交代码后若提示如下

*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <left@left.localdomain>) not allowed

需要知道提交代码的人是谁,输入用户名以及用户邮箱即可,--global为全局设定

git config --global user.name "jayZhang"
git config --global user.email "***@*"

注册完后重新提交代码

git commit -m "备注信息"

查看提交信息

git log

显示的记录信息

commit a807111a632c1fb175d5d6685d9e38560f04715c (HEAD -> master, origin/master)
Author: Left23333 <49427269+Left23333@users.noreply.github.com>
Date: Sat Apr 11 17:37:29 2020 +0800
2020.4

若修改了代码,查看哪些文件出现了改动

git status

查看该文件修改的具体内容

git diff main.c

重置

git reset

查看具体某一条的提交信息

git show a807111a632c1fb175d5d6685d9e38560f04715c

回退某一次提交

git revert a807111a632c1fb175d5d6685d9e38560f04715c

设置全局编辑器使用vim

git config --global core.editor vim

克隆托管平台的代码

git clone https://仓库域名地址

要push的url

git remote add origin https://github.com/your_name/your_project_name

把远程仓库和本地同步,消除差异

git pull origin master --allow-unrelated-histories

push到远端托管平台

git push -u origin master

已经克隆过远端代码,需要更新远端代码到本地时,会比较远端与本地代码区别,选择性下载

git pull
posted @   Left23333  阅读(245)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示