常用的 Git 命令行操作
Git 是一个开源的分布式版本控制系统,它可以帮助开发者跟踪代码的变更历史。以下是一些常用的 Git 命令行操作:
-
初始化仓库:
git init
-
克隆远程仓库:
git clone [url]
-
添加文件到暂存区:
git add [file]
-
提交更改:
git commit -m "[commit message]"
-
查看提交历史:
git log
-
查看当前状态:
git status
-
拉取远程仓库的更新:
git pull [remote] [branch]
-
推送本地更改到远程仓库:
git push [remote] [branch]
-
查看分支:
git branch
-
创建新分支:
git branch [branch-name]
-
切换分支:
git checkout [branch-name]
-
合并分支:
git merge [branch-name]
-
删除分支:
git branch -d [branch-name]
-
解决合并冲突:
当 Git 无法自动合并时,你需要手动解决冲突,然后再次提交。 -
查看远程仓库:
git remote -v
-
添加远程仓库:
git remote add [remote-name] [url]
-
重命名分支:
git branch -m [old-branch-name] [new-branch-name]
-
查看文件差异:
git diff
-
撤销工作目录的更改:
git checkout -- [file]
-
查看当前配置:
git config --list
-
设置全局配置:
git config --global user.name "[your name]" git config --global user.email "[your email]"
-
创建标签:
git tag [tag-name]
-
删除标签:
git tag -d [tag-name]
-
推送标签到远程仓库:
git push origin [tag-name]
-
检出特定标签:
git checkout [tag-name]
这些命令是 Git 操作的基础,通过它们你可以进行日常的版本控制任务。
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Eternal Night
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果