转自:日拱一卒~的gitee常用命令
常用命令
1.从远程仓库克隆项目到本地
git clone <项目地址 > # https/ssh 地址皆可以
2.初始化本地仓库.
git init # 创建本地仓库
3.本地仓库与远程仓库关联.
git remote add <仓库名> <仓库地址> # 仓库名自定义 例如:origin
4.查看仓库名.
git remote # 查看远程仓库的仓库名,加-v 查看仓库名和地址
5.更换远程仓库地址.
git remote set-url <仓库名> <仓库地址> #
6.将文件添加添加到暂存区.
git add . # . 代表所有,可以指定为具体文件
7.将暂存区中的文件提交到本地仓库.
git commit -m “<备注说明>” #
8.查看所有分支.
git branch # 查看本地分支,加-a查看本地分支和远程分支,结果列表中前面标*标识当前使用分支.
9.创建分支.
git branch <分支名称 >
10.切换分支.
git checkout <分支名称> #
11.将本地仓库的文件推动到远程仓库.
git push <仓库名> <分支名称> # 推送时建议先(pull)更新一下
12.将远程仓库中更新到本地.
git pull <仓库名> <分支名称> #
13.修改远程仓库名称.
git remote rename <旧名称> <新名称> #
14.查看提交记录
git log #
15.回滚提交
#Reset会把后面提交的记录直接删掉
git reset --hard [commit hash] # 例如:git reset --hard 7b8bcaa0b02959126b923fe554824fa9df1dfd87
16.分支合并到主分支上
git merge <分支名称>
常见错误
1.提交缓存区中内容到本地仓库
1.1.报错信息如下:
D:\xx\xx>git commit -m"初始化"
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'admin@DESKTOP-NHBTH4U.(none)')
1.2.报错原因:
出现错误的原因是因为无用户信息
1.3.解决方案:
# 1.添加你的邮箱
git config --global user.email "xxxx@qq.com"
# 2 添加你的昵称
git config --global user.name "name"
2.本地仓库提交至远程仓库时
2.1.报错信息如下:
D:\xxx\xxx>git push origin master
To https://gitee.com/xxx/xxx.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/xxx/xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
2.2.报错原因:
出现错误的主要原因是gitee中的README.md文件不在本地代码目录中
2.3.解决方案:
# 1.合并代码
git pull --rebase origin master
# 2.再次提交
git push origin master
————————————————
版权声明:本文为CSDN博主「日拱一卒~」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42069837/article/details/113405445