git常用命令

git常用命令

初始化
git init
拉取远程分支代码
git clone [url]
本地与服务端同步
git pull [remote] [branch]
添加指定文件到暂存区
git add [dir]
本地提交
git commit -m [message]
远程提交
git push [remote] [branch] # remote:origin 
查看本地所有分支
git branch
查看远程所有分支
git branch -r
新建一个分支,但依然停留在当前分支
git branch [branch-name]
切换本地分支
git checkout [branch]
新建一个分支,并切换到该分支
git checkout -b [branch]
合并指定分支到当前分支
git merge [branch]
重置暂存区与工作区,与上一次commit保持一致
git reset --hard
重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
git reset [commit]
重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
git reset --hard [commit]
# 添加远程仓库
git remote add origin https://e.coding.net/alenyao/fsj-ali/mod-jtlsp-sync.git
# 删除远程连接
git remote rm origin
# 提交
git push -u origin master
# 把远程分支拉到本地
git fetch origin dev
# 显示修改文件
git status
# 显示修改内容
git diff readme.txt

1.回滚本地代码

git reset --hard 1c4f74feb2381a1835bd6eb0dbb377992505f769

2.覆盖远程代码

git push origin branch-name --force
git push origin develop_zy --force
git push origin develop-new --force
git push origin master-finance --force

3.git标签常用命令

git tag <lightweght_name>:为当前分支所在的提交记录打上轻量标签。
git tag <lightweght_name> <commit SHA-1 value>:为某次具体的提交记录打上轻量标签。
git tag -a <anotated_name> -m <tag_message>:为当前分支所在的提交记录打上附注标签。
git tag:列出所有的标签名。
git tag -d <tag_name>:删除某个标签,本质上就是移除 .git/refs/tags/ 中对应的文件。
git show <tag_name>:显示标签对应提交记录的具体信息。
git push <remote> <tag_name>:推送某个标签到远程仓库。
git push <remote> --tags:推送所有标签到远程仓库。
git push <remote> --delete <tag_name>:删除远程仓库中的某个标签。

4.设置git pull时免登录,在.git/config文件中添加一下配置

[credential]
    helper = store
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值