git和repository命令

 

git常用命令
 
git log         // 查看当前库的git log信息
git status ./   // 查看当前库的状态
git diff ./     // 比较当前库的修改情况
git add ./      // 将当前库的代码修改提交到暂存区
git commit ./   // 将代码提交到本地分支
git commit --amend ./   // 追加修改
git reset HEAD~1    // 将当前库恢复到HEAD的上一个版本1234567
其他命令
 
git config -l // 参看配置信息
git show HEAD^ // 查看HEAD的上一个版本信息
git show HEAD~4 // 查看HEAD的上溯4代的信息
git reset --hard HEAD^^ // 回退两个版本
git reset --hard 8308f03 // 回退到指定的commitID前7位的版本
git clean -dfx //清除库上没有的东西
git remote -v //  参看远程仓库
git branch -a // 参看远程分支
git log --oneline --decorate --graph --all // 图像显示git log信息
git log --pretty=format:"%h - %cd %s" --graph // 列出指定格式的log
git log -since="2 weeks ago" // 显示2周前到现在所有的历史记录
远程同步
# 下载远程仓库的所有变动
$ git fetch [remote]
# 显示所有远程仓库
$ git remote -v
# 显示某个远程仓库的信息
$ git remote show [remote]
# 增加一个新的远程仓库,并命名
$ git remote add [shortname] [url]
# 取回远程仓库的变化,并与本地分支合并
$ git pull [remote] [branch]
# 上传本地指定分支到远程仓库
$ git push [remote] [branch]
# 强行推送当前分支到远程仓库,即使有冲突
$ git push [remote] --force
# 推送所有分支到远程仓库
$ git push [remote] --all
撤销
 
# 恢复暂存区的指定文件到工作区
$ git checkout [file]
# 恢复某个commit的指定文件到暂存区和工作区
$ git checkout [commit] [file]
# 恢复暂存区的所有文件到工作区
$ git checkout .
# 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
$ git reset [file]
# 重置暂存区与工作区,与上一次commit保持一致
$ git reset --hard
# 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
$ git reset [commit]
# 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致
$ git reset --hard [commit]
# 重置当前HEAD为指定commit,但保持暂存区和工作区不变
$ git reset --keep [commit]
# 新建一个commit,用来撤销指定commit
# 后者的所有变化都将被前者抵消,并且应用到当前分支
$ git revert [commit]
# 暂时将未提交的变化移除,稍后再移入
$ git stash
$ git stash pop12345678910111213141516171819202122232425262728293031
 
repo常用命令
 
repo init -u URL -b ........ // 创建.repo
repo upload // 将代码提交到gerrit.
repo abandon master // 放弃master分支
repo forall -c "git reset --hard HEAD" // 所有代码执行git命令,回退到HEAD
// repo sync相当于git clone会把repository中的所有内容拷贝到本地,非首次运行repo sync相当于更新和合并.
// repo sync会更新.repo下面的文件,如果在merge的过程中出现冲突,这需要手动运行git rebase --continue.
repo sync -c -j 4
repo start master --all // 创建新分支

 

转载于:https://www.cnblogs.com/wdyaoyao/p/10820181.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值