本文共 1575 字,大约阅读时间需要 5 分钟。
安装Git是Windows用户的首选方式。推荐从官方网站下载安装包(如网速较慢请切换至镜像地址),选择默认参数完成安装。
安装完成后,打开“开始菜单” -> “Git” -> “Git Bash”可以看到命令行界面,确认Git已成功安装。
最后一步配置用户信息:
git config --global user.name "Your Name"git config --global user.email "email@example.com"
初始化Git仓库使用 git init 命令。
将文件添加到Git仓库需两步:
git add <file> 可多次添加多个文件。git commit -m "commit message" 或 git commit -am "commit message" 提交。git reset --hard commit_id 可回到指定版本。git log,重返未来用 git reflog。git checkout -- file 恢复。git reset HEAD <file> 后重复上述步骤。使用 git rm 删除文件,提交前慎重操作,无法恢复最近修改。
git remote add origin git@server-name:path/repo-name.git。git push -u origin master,后续用 git push origin master。Git的分布式特点使其不依赖远程库,仅在需要时同步更新。
使用 git clone 克隆仓库,如:
git clone git@github.com:michaelliao/gitskills.git
支持多协议,ssh 最佳。
git branch;git branch name;git checkout name;git checkout -b name;git merge name;git branch -d name。解决Git合并冲突时,手动编辑文件后提交。
查看分支历史:git log --graph。
git tag tagName;git tag -a tagName -m "msg";git tag -d tagName;git push origin tagName;git push origin :refs/tags/tagName。合并时使用 --no-ff 保留分支记录。
git stash 存储现场,再修复。git remote -v;git push origin branch-name;git checkout -b branch-name origin/branch-name;git branch --set-upstream branch-name origin/branch-name;git pull。整理本地提交历史,使用 git rebase。
本文内容基于廖雪峰技术博客整理,详细操作步骤可参考原文链接。
转载地址:http://axtk.baihongyu.com/