Git 常用操作

1. 取消 merge

1) 先用 git reflog 查看操作日志

2) 使用 git reset --hard HEAD@{x} 强制回到你需要的分值 

 

2. 创建新分支

git checkout -b newBranch

 

3. 提交到远程分支

git push origin newBranch

 

4. 将本地分支指向远程分支

git push -u origin newBranch

 

5. 将当前分支提交到新分支

git push origin HEAD:newBranch

 

6. 批量取消 add

例如批量取消 .iml 文件的 add

git reset HEAD $(git ls-files | grep .iml)

 

7. 暂存当前修改

git stash 暂存当前修改

切换到其他分支, 修改, 切回原来分支

git stash list 查找暂存内容

git stash apply stash@{1} 恢复暂存内容

 

8. 显示远程服务信息

git remote show origin

origin 为远程 repository 名

 

9. 添加远程分支

git remote add <别名> <url>

 

10. 初始化项目

# 克隆项目到本地
git clone git@gitlab.corp.qunar.com:campus2015/training2.git

# 切换到 training2
cd training2

# 新建分支并切换到新的分支, 现在这个分支在本地, newBranch 是分支名, 请根据自己的需要命名自己的分支
git checkout -b newBranch

# 回到上一级目录
cd ..

# mvn 初始化项目, 这一步可能会比较慢, 可以使用 idea 新建项目替代这一步
mvn archetype:generate -DgroupId=com.qunar.training -DartifactId=training2 -Dversion=1.0.0 -DinteractiveMode=false -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=5-SNAPSHOT

# 进入项目目录
cd training2

# 添加本地未添加的文件 pom.xml 和 src 文件夹
git add pom.xml src

# 提交一次
git commit -m 'first commit'

# push 到远程分支 newBranch
git push -u origin newBranch

 

 

转载于:https://www.cnblogs.com/zemliu/p/3711829.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值