基础设置
设置用户名和邮箱
1 2
| git config --global user.email "[email protected]" git config --global user.name "xxx"
|
设置代理
1 2 3 4 5 6 7
| git config --global http.https://github.com.proxy http://127.0.0.1:58591
git config --global http.proxy http://127.0.0.1:58591 git config --global https.proxy https://127.0.0.1:58591
git config --global --unset http.proxy git config --global --unset https.proxy
|
创建git仓库
1 2 3 4 5 6
| git init git remote add origin https://github.com/用户名/仓库名.git
git remote add origin <用户名>@服务器ip:/仓库位置/仓库名.git git checkout -b xxx git checkout xxx
|
“origin” 只是一个常用的命名约定,用于表示远程仓库的别名。实际上,你可以使用任何你喜欢的自定义名称来代替 “origin”。这个名称只是用来标识远程仓库的名称,方便你在后续的操作中引用它。所以,你可以根据自己的喜好和项目需求来选择一个有意义的名称作为远程仓库的别名。
提交常用命令
1 2 3
| git add . git commit -m "" git push
|
拉取常用命令
1 2 3
| git clone [email protected]:/var/repo/hexo.git git clone https://github.com/xxx/xxxx.git git clone -b xxx https://github.com/xxx/xxxx.git
|
查询当前git状态常用命令
1 2 3 4
| git branch -avv git remote -v git branch --set-upstream-to=REMOTE_NAME/REMOTE_BRANCH_NAME git remote show origin
|
重置本地仓库
使用以下命令删除所有未跟踪的文件:
该命令中的选项-f表示强制删除文件,-d表示删除未跟踪的目录以及其中的文件。
放弃所有本地更改并拉取远程仓库的代码。你可以使用git reset --hard命令来重置分支,并指定远程分支作为重置的目标。以下是完整的命令:
1
| git fetch origin && git reset --hard origin/分支名
|
执行该命令后,它会先从远程仓库获取最新的提交记录,然后将本地分支重置为与远程分支一致的状态,丢弃所有本地的更改。最后,你可以使用git pull命令来拉取远程仓库的最新代码并进行合并:
执行上述两个命令后,你应该放弃了所有本地的更改,并将本地分支更新为与远程仓库一致的状态。记得在执行这些命令之前备份任何你想要保留的重要更改。
分支操作
1 2 3 4 5
| git checkout origin 分支名 git checkout -b origin 分支名 git branch -d 分支名 git push -d origin 分支名 git merge 分支名
|
回滚版本
1 2
| git reset --hard commit_sha git push origin HEAD --force
|