Git 学习笔记
Git 学习笔记
安装Git:
- 从 官网 下载,并在 Github 上下载相关汉化包
配置Git:
- 运行以下命令配置 Git 用户名和邮箱
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
创建和克隆仓库:
- 创建一个新的Git仓库:
git init。 - 克隆一个远程仓库到本地:
git clone [repository-url]。
文件操作:
- 添加文件到暂存区:
git add [file]。 - 删除文件:
git rm [file]。 - 移动或重命名文件:
git mv [old-file] [new-file]。
提交更改:
- 提交暂存区的文件到仓库:
git commit -m "Commit message"。
分支管理:
- 查看所有分支:
git branch。 - 创建新分支:
git branch [branch-name]。 - 切换分支:
git checkout [branch-name]。 - 合并分支:
git merge [branch-name]。 - 删除分支:
git branch -d [branch-name]。
查看状态和日志:
- 查看仓库状态:
git status。 - 查看提交历史:
git log。
远程仓库操作:
- 添加远程仓库:
git remote add [remote-name] [repository-url]。 - 推送到远程仓库:
git push [remote-name] [branch-name]。 - 从远程仓库拉取:
git pull [remote-name] [branch-name]。
标签管理:
- 创建标签:
git tag [tag-name]。 - 查看所有标签:
git tag。 - 推送标签到远程仓库:
git push --tags。
一些有用的Git命令:
- 查看差异:
git diff。 - 忽略文件:编辑
.gitignore文件。 - 撤销暂存区文件:
git reset HEAD [file]。 - 撤销工作目录文件:
git checkout -- [file]。

浙公网安备 33010602011771号