git常见问题

记录git日常使用时候遇到的一些问题

  •  修改提交记录
撤销上一个提交,然后用一个新的提交替代
git commit --amend

rebase合并之前已经提交的n个提交(原提交保留仅修改提交commit文字)
1.git log --oneline (查看提交记录)
2.git rebase -i 开始版本 结束版本 (前开后闭,结束版本不填默认最后一次提交)
3.进入vi界面将需要修改的commit记录前面的pick改成r,wq退出
4.进入vi界面修改commit记录,wq退出,合并结束

 

  •  删除分支

 git branch -d branchname(删除本地)

 git push origin --delete branchname(删除远程)

 

  •  删除缓存区所有修改
git checkout -f

 

  • git批量删除本地分支
git branch -a | grep -v -E 'master|brancha|branchb' | xargs git branch -D

-v除了

-E正则

上面的意思就是除了master,brancha,branchb其他的本地分支都删除、分支名必填。

 

  • git 强制覆盖本地修改
git reset --hard 分支名称

 

  • git解决每次操作需要输入密码的问题,这个设置相当于记住密码。
git config --global credential.helper store

 

  •  git pull时候Unlink of file '.git/objects/pack/pack-***.pack' failed. Should I try again? (y/n) y
git gc --auto

 

  • git储藏
  • 将没有提交的变更存储起来

git stash

  • 如果想存储的同时为本次存储起个名字为"hello"

git stash save “hello”

  • 查看已经完成的历史存储

git stash list

  • 想弹出所存储的内容时候

git stash pop

  • git stash pop弹出的是最后一次stash起来的内容,如果想弹出之前stash起来的内容的话,先使用命令查看stash栈中的内容(命令git stash list),假设弹出倒数第二次的存储

git stash apply stash@{1}

  • 删除历史所有存储

git stash clear

注:stash pop操作成功时,本次存储将被删除,stash apply 所对应的存储不会被删除。

 

  • git远程仓库
  • 从一个远程仓库拉代码,假设新的远程仓库地址为: https://git.xx.net/xxx/project

git clone https://git.xx.net/xxx/project

  • 查看远程仓库:

git reomote -v

  • 假设新的远程仓库地址为: https://git.xx.net/xxx/project

git remote set-url origin https://git.xx.net/xxx/project

 

  • git全局配置
  • 查看配置:

git config -l

  • 设置配置:姓名、邮箱

git config --global user.name "xx"

git config --global user.email "xx@xx.com"

posted @ 2018-03-09 10:00  扶不起的刘阿斗  阅读(170)  评论(0编辑  收藏  举报