Git备忘

常用命令

git checkout -B master origin/master

其实是以远程分支为准reset本地分支

git remote -v
git branch -v
git push [remote-name] [branch-name]
git checkout - -  a.rb
git checkout .
git reset HEAD file
git  push origin --delete 分支名
git  push origin :分支名
git config core.editor = vim
git reset --soft HEAD@{1}
HEAD@{1} gives you "the commit that HEAD pointed at before 
it was moved to where it currently points at".
git pull origin --tags
git branch | grep 'KAP*' | xargs git branch -D
ssh://git@ssh.github.com:443/yourname/reponame.git
git merge --abort
git log --graph --pretty=oneline
git tag | xargs -I@ git log --format=format:"%ci %h @%n" -1 @ | sort | tail -1 | awk {'print $5'}

搭建一个git服务器

在服务器安装git 加一个git用户:sudo adduser git 用git用户登陆服务器,在home目录新建.ssh目录,里面新建authorized_keys文件 在需要登陆的用户的机器运行ssh-keygen,生成id_rsa和id_rsa.pub,把id_rsa.pub的内容拷贝到上面的authorized_keys里面,一个用户占一行 在git用户的home目录,新建项目 sudo git init --bare sample.git 在客户端,clone下来 git clone git@[server]:sample.git

      [server]为服务器IP或/etc/hosts文件里面映射的域名

然后在客户端这边加代码,推送上去

合并多个commit为一个

找到最下面一个commit hash值,
git rebase -i hash
除了第一个,其他的都改成squash或s