本地分支重命名
git branch -m oldbranchname newbranchname
删除本地分支
git branch -D ranchname
储藏 stash
git stash save "save message"
: 执行存储时,添加备注,方便查找,只有git stash
也要可以的,但查找时不方便识别git stash list
:查看stash了哪些存储git stash drop stash@{\$num}
:丢弃stash@{$num}存储,从列表中删除这个存储git stash clear
:删除所有缓存的stashgit stash apply
: 应用你刚刚实施的储藏git stash apply stash@{2}
: 应用更早的储藏
基于develop新建一个分支
git checkout -b xxx(分支名) origin/develop
提交代码的基本流程
- 1、
git status
查看改了哪些代码 - 2、
git log
查看log - 3、
git add -A
将代码放到本地缓存区 - 4、
git commit -m "提交信息xxxx“
将代码提交到本地 - 5、
git fetch --all
拉远程的代码 - 6、
git rebase origin/develop
与远程的代码融合(可能会有冲突) - 7、
git log
查看自己的代码是否已提交 - 8、
git branch
查看自己当前所在分支 - 9、
git push origin xxx(当前代码所在分支名)
将代码push到远程分支
git commit 之后 进行了fetch rebase 操作,又改了代码
- 1、
git add -A
- 2、
git commit --amend
- 3、
git fetch --all
- 4、
git rebase origin/develop
- 5、
git push origin xxx(当前代码所在分支名)
git不小心push了错误代码,怎么撤回
- 1、
git log
- 2、
git reset fda12b7cda7a6a70d3ea2adb565e5bfa3848bfff(你提交代码之前的commit ID)
- 3、
git add -A
- 4、
git commit -m "提交信息xxxx“
- 5、
git push origin xxx(当前代码所在分支名) -f (需要强制push)
merge到develop分支
- 1、
git rebase origin/develop
(在自己的分支上rebase develop分支的代码) - 2、
git log
- 3、
git checkout develop
切换到develop分支上 - 4、
git merge xxxx(自己的分支名)
- 5、
git log
- 6、
git push origin develop
git解决冲突(当rebase代码的时候遇到冲突 )
- 1、手动解决冲突
- 2、
git add -A
- 3、
git rebase --continue
- 4、
git push origin xxxx(自己的分支名)
git clone代码的时候弹不出密码框了
git config --system --unset credential.helper
每次git操作 都要输入密码
-
git config --global credential.helper store
-
然后执行 git 操作,输入一遍密码后就会记录密码,以后就不用输入了
其它操作
- 查看最近一次commit的内容
git log -n1 -p
- 如果你的提交信息(commit message)写错了且这次提交(commit)还没有推(push), 你可以通过下面的方法来修改提交信息(commit message);如果你已经推(push)了这次提交(commit), 你可以修改这次提交(commit)然后强推(force push), 但是不推荐这么做。
git commit --amend --only -m 'xxxxxxx'
- 只是单个提交(commit)里的用户名和邮箱不对
git commit --amend --author "name <xxx@mydomain.com>"
- 从一个提交(commit)里移除一个文件
git checkout HEAD^ myfile
git add -A
git commit --amend