git 常用命令:
git init
git clone <仓库地址>
git clone -b <分支名tag or branch> <仓库地址>
git add .
git commit -m “message”
git status
git pull
git push
git branch <分支名>
git checkout <分支名tag or branch>: 切换到指定分支。
git tag v0.0.1
git push origin v0.0.1
删除远程仓库文件夹
git rm -r -n --cached 文件/文件夹名称
git rm -r --cached 文件/文件夹名称
git status
git commit -m "删除文件"
git push
git 下载与安装:https://git-scm.com/
git 绑定 github:
git config --global user.name "myname"
git config --global user.email "myname@email.com"
一、创建于初始化
git init: 在当前目录初始化一个新的 Git 仓库。
git clone [url]: 克隆远程仓库到本地。
二、基本操作
git add . : 将文件添加到暂存区。
git commit -m “message”: 提交暂存区的文件到本地仓库。
git status: 显示工作区和暂存区的状态。
git diff: 显示文件修改的差异。
三、分支与合并
git branch: 列出本地分支,创建或删除分支。
git checkout [branch]: 切换到指定分支。
git merge [branch]: 合并指定分支到当前分支。
git rebase [branch]: 将当前分支变基到指定分支。
四、远程操作
git remote -v: 显示远程仓库的详细信息。
git fetch [remote]: 从远程仓库拉取最新变更。
git pull [remote] [branch]: 拉取远程分支并合并到本地分支。
git push [remote] [branch]: 将本地分支推送到远程仓库。
五、撤销与重置
git reset [file]: 从暂存区撤销文件的更改。
git revert [commit]: 撤销指定提交的更改。
git checkout – [file]: 恢复文件到最近一次提交的状态。
六、查看历史与日志
git log: 显示提交日志。
git show [commit]: 显示某次提交的详细内容。
将本地仓库与GitHub仓库关联:
git remote add origin https://github.com/YourGitHubUsername/YourRepository.git
将文件添加到暂存区
git add test.py
提交暂存区的文件到本地仓库
git commit -m “main”
拉取远程并合并到本地。
git pull --rebase origin master