日常使用中的git操作,有关key生成,冲突处理,修改远程仓库,强制push到远程等

git命令:
git ssh key生成: $ssh-keygen -t rsa -C “djfyaci”
查看ssh key: cd ~/.ssh
cat id_rsa.pub
pull失败: git remote git@github.com:djfyaci/learngit.git
打tag :
git tag publish/0.2.0
git push origin publish/0.2.0
git branch --set-upstream-to=origin/daily/0.2.1 daily/0.2.1 关联
删除tag: git tag -d v1.0.0
推送本地分支到远程
git push origin guo-dev
强制push到远程分支:慎用些命令
git push --force origin daily/1.2.99:daily/1.2.99

全局配置

git config --global user.name "My Name"
git config --global user.email "my@email.com"
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.df diff
git config --global alias.br branch
git config --global alias.plo  pull origin
git config --global alias.pso  push origin
git config --global alias.cm 'commit -m'
git config --global alias.ll 'log --oneline'
git config --global alias.last 'log -1 HEAD --stat'
git config --global alias.gl 'config --global -l'
git config --global alias.se '!git rev-list --all | xargs git grep -F'

git 修改远程库指向
方法一:修改命令 git remote set-url origin [url]
方法二:先删后加 git remote rm origin git remote add origin [url]
方法三:直接修改config文件

git 撤销本一修改
git checkout –
此命令会使用 HEAD 中的最新内容替换掉你的工作目录中的文件。已添加到暂存区的改动以及新文件都不会受到影响。假如你想丢弃你在本地的所有改动与提交,可以到服务器上获取2.最新的版本历史,并将你本地主分支指向它:
git fetch origin
git reset --hard origin/master

git clean
一般 git clean都是配合git reset 使用的
使用git clean 需要注意 加上x会把.gitignore下面的文件也删除了,最好不要加x
git clean -df
参考:http://blog.csdn.net/leon1741/article/details/54314565
如果你有的修改已经加入暂存区的话
那么
git reset --hard
git clean -xdf

如果没有加入暂存区的话
git checkout . && git clean -xdf*

强制push到远程分支:慎用些命令
git push --force origin daily/1.2.99:daily/1.2.99
执行rm –rf 删除快捷方式时一定要加引号,防止源文件被删除

解决冲突
先将你的改动缓存到本地,或者直接 git rest --hard master~1 丢弃
git stash
然后拉取更新
git pull
git stash pop
然后修改并合并冲突
git push

解决merging
You have not concluded your merge (MERGE_HEAD exists). Please commit
your changes before you can merge.
问题的原因是, 以前的pull 之后merge 失败, Git 进入conflict 状态。
解决办法:

  1. Undo the merge and pull again.
    To undo a merge:
    git merge --abort [Since git version 1.7.4]
    git reset --merge [prior git versions]
  2. Resolve the conflict.
  3. Don’t forget to add and commit the merge.
  4. git pull now should work fine.

查看远程日志
git log origin/master -n 3
查看日志(单行)
git log --pretty=oneline

忽略已经被提交跟踪的文件
解决方法1: 正确的做法应该是:git rm --cached logs/xx.log,然后更新 .gitignore 忽略掉目标文件,最后 git commit -m “We really don’t want Git to track this anymore!”
解决方法2: logs整个目录删除,然后添加忽略后再提交,当方法1不起作用时,有可能是跟踪了整个目录

统计代码行数
统计某一人的增删行数
git log --author=“yourname” --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - KaTeX parse error: Expected 'EOF', got '}' at position 3: 2 }̲ END { printf "…name\t"; git log --author="$name" --pretty=tformat: --numstat | awk ‘{ add += $1; subs += $2; loc += $1 - $2 } END { printf “added lines: %s, removed lines: %s, total lines: %s\n”, add, subs, loc }’ -; done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值