赞
踩
1. git clone url // 从url clone最新代码
2.git checkout -b mybranch // 新建分支并且换到mybranch,然后在mybranch上开发代码
3.git status // 查看代码状态
4.git add . // 将工作区代码加到暂存区(有时需要一个个添加 git add filename )
5.git commit // 将暂存区代码添加到本地仓库,需要添加详细注释(git commit -m "注释")
6.git review // 将本地库代码同步到远程仓库 类似于 git push
当在自己的分支上开发完成之后,需要提交代码
1.git checkout master // 切换到主分支
2.git pull // 拉取主分支最新代码
3.git checkout mybranch // 切换到自己的代码分支
4. git status // 查看代码状态
5.git add . // 将代码从工作区添加到暂存区
6.git commit // 将代码从暂存区,添加到本地仓库,添加详细注释
7.git rebase master // 同步master代码 (自行了解rebase作用)
8. 如果有冲突,解决冲突
9.git add // add完 不需要commit(切记)
10.git rebase --continue
11.git review // 提交到远程仓库
(git rebase 和 git merge 的区别自行了解)
git log // 查看commit日志(重要)
git reflog // 查看详细操作日志(重要)
git branch // 查看分支
git branch mybranch // 新建分支 mybranch
git checkout mybranch //切换到mybranch分支
git branch -m oldbranch newbranch // 修改分支名称
git reset ID // 回到某个节点(一般使用以下形式)
git reset --soft HEAD^ // 不删除工作空间改动代码,撤销commit,不撤销git add . (git reset ID --soft HEAD^)
git reset --hard HEAD^ // 删除工作空间改动代码,撤销commit,撤销git add .
注意:完成这个操作后,就恢复到了上一次的commit状态
git reset --mixed HEAD^ // 等同于默认 git reset HEAD^ 效果自己体会
(不删除工作空间改动代码,撤销commit,并且撤销git add . 操作
这个为默认参数,git reset --mixed HEAD^ 和 git reset HEAD^ 效果是一样的)
切换分支不能切换,需要保存工作取内容
git stash // 保存工作区的内容(进度),再运行git status 就是干净的工作区,git stash save 'message...'可以添加一些注释
git stash list // 显示保存进度的列表
git stash pop [–index] [stash_id]
git stash pop 恢复最新的进度到工作区
git stash pop --index 恢复最新的进度到工作区和暂存区
git stash pop stash@{1}恢复指定的进度到工作区。stash_id是通过git stash list命令得到的
git stash apply [–index] [stash_id] //除了不删除恢复的进度之外,其余和git stash pop 命令一样
git stash drop [stash_id] // 删除一个存储的进度。如果不指定stash_id,则默认删除最新的存储进度
git stash clear // 删除所有存储的进度
git branch --set-upstream-to=origin/<branch> mybranch // 将本地分支关联到远程分支
gerrit 提交代码没有出现代码问题但是-1,使用replay -> recheck->send 重新检查(备注)
据说只要将代码交给git管理,代码轻易不会丢掉,所以可以放心尝试,自己解决了问题就明白了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。