为了熟练以及备忘使用github方式将代码修改,提交,查找历史修改记录等操作,现写该文marker。
简单命令注解
1,使用git diff查看当前修改内容,确认修改内容是否正确 , 后面带的参数不同,作用范围不同,列举如下:
git diff //查看当前工程分支所有的修改。
git diff ./ //查看当前目录的修改
git diff xx/yy.c //查看xx路径下的yy.c文件修改
git diff xx/yy.c > xx/yy.diff //将xx路径下的yy.c文件修改内容保存到xx目录下的yy.diff 文件中,可以方便查阅。
git diff [first-branch]...[second-branch] //Shows content differences between two branches //查看两个分支之间不同之处
2,列出要提交的所有新文件或修改过的文件,确认你修改了那些文件。
git stauts //后面不带参数,列出该工程分支要提交的修改过的文件或新文件
git stauts ./ //后面带参数./,列当前目录修改过的文件或要提交的新文件
3,放弃修改,或者需要还原到之前未修改的状态
git checkout --<file> //to discard changes in working directory //去除修改,回复原来
例如
git checkout xx/yy.c //还原xx目录下的yy.c文件。yy.c的修改内容将被修改。
4,提交暂存
git add * //提交暂时存放当前分支所有的修改 等同git add -A
git add xx/yy.c //提交暂时存放指定的xx/xx/xx.c文件
5,提交,提交之后会生成一串ID, 后续的提交内容可以根据ID来查阅。
git commit -m "注释说明" // 提交已经暂存的代码
6,查看提交记录
git log //查看该工程分支所有的提交记录
git log -p -2 //查看近两次提交的内容, 2可以自定义。
git show [commit id] //Outputs metadata and content changes of the specified commit//根据commit ID 查看该次修改提交的内容
7,提交之后,撤销提交以及修改
$ git reset [commit id] //在[commit id]之后撤消所有提交,在本地保留更改 //Undoes all commits afer [commit id], preserving changes locally
$ git reset --hard [commit id] //放弃所有历史记录和对指定提交的更改 //Discards all history and changes back to the specified commit
8,代码分支创建切换删除
$ git branch -a //显示当前工程的所有分支 //Lists all local branches in the current repository
$ git branch [branch-name] //创建新的分支 //Creates a new branch
$ git checkout [branch-name] //切换到分支branch-name //Switches to the specified branch and updates the working directory
$ git merge [branch] //Combines the specified branch’s history into the current branch
$ git branch -d [branch-name] //删除分支branch-name //Deletes the specified branch
工作流
你的本地仓库由 git 维护的三棵“树”组成。第一个是你的 工作目录,它持有实际文件;第二个是 缓存区(Index),它像个缓存区域,临时保存你的改动;最后是 HEAD,指向你最近一次提交后的结果。
你可以计划改动(把它们添加到缓存区),使用如下命令:
git add <filename>
git add * //提交当前分支所有的修改
这是 git 基本工作流程的第一步;使用如下命令以实际提交改动:
git commit -m “代码提交信息”
现在,你的改动已经提交到了 HEAD,但是还没到你的远端仓库。
以下是参考使用连接:
https://www.runoob.com/git/git-tutorial.html
https://www.bootcss.com/p/git-guide/
https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2