博主头像
跳跳熊QWQ534的博客

梦想成为大糕手


Git初使用

Git初次使用记录

[window type="red" title="git设置用户名和邮箱"] [/window]

git config --global user.name "用户名"
git config --global user.email "邮箱"

[window type="red" title="git设置用户名和邮箱"]git 创建本地仓库
新建文件夹,打开git命令行
[/window]

git init

[window type="red" title="git提交"] [/window]

工作区修改后执行
git add filename
将某一文件添加至暂存区,或者
git add .
将所有文件添加至暂存区
然后
git commit -m "备注"
将暂存区中的文件添加至仓库
git log 查看提交记录
git log --stat 查看每次提交时修改了哪些文件

[window type="red" title="git比较版本区别"] [/window]

git diff                              比较的是工作区与暂存区的区别
git diff --cached                     比较的是暂存区和仓库的区别
git diff HEAD                         比较的是工作区与仓库的区别
git reset --hard [commit id]          可以将代码回溯至任一节点

[window type="red" title="git分支"] [/window]

git branch                            查看当前项目有哪些分支
git checkout -b name                  创建分支
git checkout name                     切换到某一分支
git merge name                        可以将当前分支与name分支合并

[window type="red" title="git链接本地仓库与远程仓库"] [/window]

git remote add origin <远程git仓库地址>
例如
git remote add origin https://github.com/xxx/xxx.git

git remote set-url origin <新的远程Git仓库地址>    更改默认远程仓库
git remote -v                                     查看当前的远程仓库
git remote rm origin                              删除远程仓库,将已经添加的名为origin的仓库删除

[window type="red" title="将本地仓库同步到远程仓库"] [/window]

git push -u origin master

[window type="red" title="从远程仓库拉取"] [/window]

git pull
发表新评论