1、创建仓库


2、克隆仓库到本地(首次拉取需要输入用户名和密码,用户名用邮箱,密码用登录gitee的密码,后面配置密钥后可以直接clone)
在命令行输出两行指令配置git才能克隆:
username:gitee账号名
useremail:gitee账号绑定的邮箱



进入拉取下来的工程目录:

使用ll命令查看.git

3、git的设计原理:
index:暂存区
objects:版本库


4、git status:获取版本状态,该命令不能再隐藏文件.git中使用

添加了文件的状态:
添加了文件到版本库的状态:

5、推送更新仓库过程
(1)添加文件到暂存区:git add filename

(2)添加暂存区到版本库:git commit -m "添加说明" (建议格式固定:添加人员:操作描述)

(3)推送文件到远程仓库:git push origin master
origin:远程仓库地址

master:仓库分支名

cd .git/
vim config
6、添加开发者协作
管理--》仓库成员管理--》开发者--》邀请

添加公钥:
进入Linux家目录使用ssh-keygen -t -rsa -c "公钥标记"

cd 到.ssh/ 文件夹下可以看到生成的公钥和私钥;
pub后缀表示公钥;

使用cat 查看公钥内容并赋值到仓库的公钥添加上;


非仓库管理源获取该仓库内容需要用ssh:可以看提示配置

git reflog于记录本地仓库的 HEAD 和分支引用(branch references)的变动历史

误删回滚:
1、在git add 之前删除 用git checkout -- .(git restore可以替代但是在未提交之前,暂未尝试成功;)

2、git add 之后 在 git commit 之前用 git restore 撤销修改;



3、在git commit 之后删除可以通过git reset --hard 版本号前几个字符进行回滚



1. 创建仓库
- 在Gitee、GitHub等Git托管平台上创建一个新的仓库。通常包括填写仓库名称、描述、是否公开等信息。
2. 克隆仓库到本地
首次克隆仓库时,可能需要在命令行中输入用户名(使用邮箱格式)和密码(登录Gitee或GitHub的密码)。为了避免每次都需要输入密码,可以配置SSH密钥。
配置Git用户信息(尽管这与克隆仓库无直接关系,但通常在开始使用Git前进行):
|---|-------------------------------------------------|
| |git config --global user.name "gitee账号名"
|
| |git config --global user.email "gitee账号绑定的邮箱"
|克隆仓库命令:
|---|---------------------------------------|
| |git clone git@gitee.com:用户名/仓库名.git
|或使用HTTPS方式(首次可能需要输入用户名和密码):
|---|-------------------------------------------|
| |git clone https://gitee.com/用户名/仓库名.git
|进入仓库目录,并使用
ll
(或ls -l
)命令查看文件,包括.git
目录(通常是隐藏的)。3. Git的设计原理
- Index(暂存区):暂存更改的文件,准备提交到版本库中。
- Objects(版本库):存储实际的文件内容和Git的历史记录。
4.
git status
- 用于获取当前仓库的状态,包括哪些文件被修改了、哪些文件是新添加的、哪些文件被暂存了等。
- 添加了文件的状态 :
git status
会显示新文件未被跟踪(untracked)。- 添加了文件到版本库的状态:文件会显示为已暂存(staged)或已提交(committed)。
5. 推送更新仓库过程
添加文件到暂存区:
|---|--------------------|
| |git add filename
|添加暂存区到版本库:
|---|-------------------------------------------|
| |git commit -m "添加说明" # 例如:"张三: 添加了新功能X"
|推送文件到远程仓库:
|---|------------------------------------------|
| |git push origin master # 或者其他分支名,如main
|注意:随着Git的发展,
master
分支可能已被重命名为main
。6. 添加开发者协作
在Gitee等平台上,通过"管理"->"仓库成员管理"->"开发者"->"邀请"来添加协作者。
添加公钥:
在Linux上生成SSH密钥对(如果还没有的话):
|---|---------------------------------------|
| |ssh-keygen -t rsa -b 4096 -C "你的邮箱"
|将生成的公钥(
.ssh/id_rsa.pub
文件的内容)添加到Gitee等平台的SSH公钥设置中。7. 误删回滚
在
git add
之前删除:|---|---------------------------------------------------|
| |git checkout -- . # 或者 git restore .(Git 2.23+)
|在
git add
之后,git commit
之前撤销修改:|---|----------------------------------------------------------------|
| |git restore filename # 或者 git checkout -- filename(较旧的Git版本)
|在
git commit
之后删除或回滚:|---|---------------------------------------------------------------|
| |git reset --hard <commit-id> # <commit-id>可以是提交的完整哈希值的前几个字符
|8.
git reflog
- 用于记录本地仓库的HEAD和分支引用的变动历史。当你不确定何时或如何进行了某些更改时,这非常有用。
通过遵循这些规范,可以更有效地使用Git进行版本控制和团队协作。