欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 社会 > git常用命令

git常用命令

2025/4/26 11:07:42 来源:https://blog.csdn.net/ZhanBiaoChina/article/details/147192541  浏览:    关键词:git常用命令

Git 常用命令
1.仓库初始化与克隆
初始化本地仓库:

git init

克隆远程仓库:

git clone <repository-url>

2.文件状态与更改
查看文件状态:

git status

查看更改内容:

git diff

3.提交更改
添加文件到暂存区:

git add <file>

添加所有更改:

git add .

提交更改:

git commit -m "commit message"

4.分支操作
查看所有分支:

git branch

创建新分支:

git branch <branch-name>

切换分支:

git checkout <branch-name>

创建并切换到新分支:

git checkout -b <branch-name>

合并分支:

git merge <branch-name>

删除分支:

git branch -d <branch-name>

5.远程仓库操作
查看远程仓库:

git remote -v

添加远程仓库:

git remote add <remote-name> <url>

推送更改到远程仓库:

git push <remote-name> <branch-name>

拉取远程更改:

git pull <remote-name> <branch-name>

6.标签操作
查看所有标签:

git tag

创建标签:

git tag <tag-name>

推送标签到远程仓库:

git push origin <tag-name>

删除标签:

git tag -d <tag-name>
git push origin :refs/tags/<tag-name>

7.版本回滚
查看提交历史:

git log

回滚到指定提交:

git reset --hard <commit-hash>

撤销最近一次提交:

git reset --soft HEAD~1

8.其他常用命令
忽略文件:
创建或编辑 .gitignore 文件,添加需要忽略的文件模式。
查看远程仓库信息:

git remote show <remote-name>

拉取所有分支:

git fetch --all

查看文件历史更改:

git log -p <file>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词