查看配置相关
git config --list
删除指定配置项
git config --global --unset user.name
设置用户信息
git config --global user.name “*”
git config --global user.email *@example.com
删除本地用户
git credential-manager uninstall
编辑用户信息
git config --global --edit
clone远程项目
git clone git://github.com//.git
查看当前状态
git status
查看忽略信息
cat .gitignore
查看当前和服务器差异
git diff(在pull完代码存在冲突的时候使用)
若要看已经暂存起来的文件和上次提交时的快照之间的差异,可以用 git diff --cached 命令。(Git 1.6.1 及更高版本还允许使用git diff --staged
查看日志
git log
撤销提交
git commit --amend
代码合并rebase
正常用的比较少
git rebase -i HEAD~3 合并最新三次提交
对应执行命令说明
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#p,选择<commit>=使用commit
#r,reword<commit>=使用commit,但编辑提交消息
#e,edit<commit>=使用commit,但停止修改
#s,squash<commit>=使用commit,但合并到上一个commit中
#f,fixup<commit>=类似于“squash”,但丢弃此提交的日志消息
#x,exec<command>=使用shell运行命令(行的其余部分)
#b,break=stop here(稍后用'git rebase--continue'继续rebase)
#d,drop<commit>=删除提交
#l,label<label>=用名称标记当前磁头
#t,reset<label>=将磁头重置为标签
#m,合并[-C<commit>|-C<commit>]<label>[#<oneline>]
# . 使用原始合并提交的
# . 消息(或单行,如果未提交原始合并)
# . 指定)。使用-c<commit>重写提交消息。
后续步骤
1、继续编辑
2、提交当前信息
3、完成后提交
use "git rebase --edit-todo" to view and edit
use "git commit --amend" to amend the current commit
use "git rebase --continue" once you are satisfied with your changes
更改提交人信息
git commit --amend --reset-author
会以当前最新的全局配置覆盖当前提交人信息
代码操作
add (可以单个文件或者文件夹)
git add *
commit
git commit -m ‘注释’
pull
git pull origin 分支
push
git push origin 分支
git push -f origin 分支(强制覆盖远程分支)
fetch
git fetch origin 分支
rebase
git rebase -i ha
git cherry-pick sha
可缩写
pick(拾取)
rwork
edit
squash(压缩)
fixup(修正)
exec(执行)
reset
git reset --hard HEAD~回退commit次数
git reset --hard HEAD -i ha
git reset --hard HEAD 文件夹(单个文件)
/**
. 指的全部数据
add . 添加全部
*/
git分支操作
1、切换分支
git checkout [分支名]
2、从远程剪贴分支并作为本地分支
git checkout -b [分支名] [远程名]/[分支名] 这个可以指定不同名字
----git checkout -b [分支名] 这个是本地和远程分支同名
git checkout [分支名] 这个是本地和远程分支同名
3、删除分支
git branch -D [分支名]
gitk 启用图形客户端查看**
git log
git 配置公钥秘钥并实现免密码登录clone
http://blog.csdn.net/accountwcx/article/details/46822257
- ssh-keygen -t rsa -C “xxxxx@xxxxx.com” -f “d:\id_rsa”
- ssh -T git@git.oschina.net
如果是git服务的连接方式是https的话就可以用这个设置下连接方式,然后就可以免密码push了
git remote set-url origin git@github.com.git
git合并分支
当前存在分支dev和master,需要把master代码合并到dev
git checkout dev
git pull
git checkout master
git pull
git checkout dev
git merge master
处理冲突
git add .
git commit -m '分支合并'
git push