git pull //更新下载最新代码
git status //查看当前code状态git checkout -- . //检出代码
git add . //提交当前文件夹下的所有修改
git add filePath //提交指定文件
git commit -a //备注比较长,是个大文本git commit -m 'commit message.' //备注长度一般
git commit --amend //修改提交过的注释,备注
git pull -r
//合并代码到本地,一般commit之后push之前执行,-r:reset
git clean -fd . // mvn 之前去除无用文件
git push origin HEAD:refs/for/branch_name //提交代码到远程分支
或者是:
git push origin HEAD:branch_name
git reset --hard <commit_id> //code恢复到commit_id 时期(可以从log上查看你想回到的地方)
#git pull //再更新到最新的code,原来修改过的,没有push的code都会删除
gitk //图形化查看提交历史记录
[
删除错误add的文件
一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)。
参数:
-r 就是向下递归,不管有多少级目录,一并删除
-f 就是直接强行删除,不作任何提示的意思
需要提醒的是:使用这个 rm -rf 的时候一定要格外小心,linux 没有回收站的
]
git合并几次commit
1).首先使用git log查看一下提交历史这样在git中看到的是2次提交,有点冗余,需要做的是将2次commit合并为一次
或者 git status 查看,eg:
$ git status
On branch master_1
Your branch is ahead of 'origin/master_1' by
2 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
该命令执行后,会弹出一个编辑窗口,2次提交的commit倒序排列,最上面的是最早的提交,最下面的是最近一次提交。
3)
修改第2行的第一个单词pick为squash,当然看一下里面的注释就理解含义了。
然后保存退出,Git会压缩提交历史,如果有冲突,需要修改,修改的时候要注意,保留最新的历史,不然我们的修改就丢弃了。修改以后要记得敲下面的命令:git add .
git rebase --continue(有的自动执行)
4)如果你想放弃这次压缩的话,执行以下命令:
git rebase --abort
5)如果没有冲突,或者冲突已经解决,则会出现如下的编辑窗口:
# This is a combination of 2 commits.
# The first commit’s message is:
add center style indent
# The 2nd commit’s message is: :q
add center style
# Please enter the commit message for your changes. Lines starting
# with ‘#’ will be ignored, and an empty message aborts the commit.
6)不过此时远程的信息仍未改变,下面操作会把修改同步到远程git仓库,再执行
git push origin HEAD:refs/for/master_1提交代码
END