1. 直接提交文件
对于git 在本地版本库中已有的文件,可以不用执行“git add”操作,直接将工作区的文件提交到版本库(非index区)
$ git commit -m "pages/mainContent.html" pages/mainContent.html
[master 78b06dc] pages/mainContent.html
1 file changed, 40 insertions(+), 31 deletions(-)
2. 使用图形方式显示分支提交日志
$ git log --graph --pretty=oneline --abbrev-commit
* a12f1eb add bin/gateway.json
* 89c8f7c modify ../reportFrontend/routes/reports.js
* 78b06dc pages/mainContent.html
* 7851316 modify /iomsSimulator/pages/css/mainContent.css
* 7f85e95 deleted
* 5d8906b Merge remote-tracking branch 'iomssimu/master'
|\
| * bcf6f18 Create README.md
| * e955bb0 Merge branch 'master' of https://github.com/solarkai/IomsSimu
| |\
| * | 3692d9d commit microservice-discovery-service1 dir
| /
* | 1ec31f7 added
* | 30aeb18 deleted Please enter the commit message for your changes. Lines starting
* | fadbdf7 modified
* | 01e298f deleted
* | a5752be deleted
* | 8760c94 deleted Please enter the commit message for your changes. Lines starting
* | b4981ab delete
* | 5a8f6c6 commit
|/
* 537d116 commit reportfrontend dir
* c49f89a commit iomssimulator dir
3. 版本库回退到指定位置
根据“git log”命令获取到回退目标的位置,如下示例:
$ git reset --hard 89c8f7c
命令格式为“git reset [<mode>] [<commit>]”。请注意,这里的几个mode参数:
- --hard: Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded(重置index区和工作区,都使用当前分支的当前版本).
- --soft:Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.(不重置index区和工作区)
- --mixed:Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action(重置index区而非工作区,这是该命令的默认模式).
4. 删除文件后恢复
误删工作区的文件后,可以将版本库中的当前分支的当前版本恢复到工作区,如下命令示例(gateway.json文件被不小心删除):
$ git checkout reportFrontend/bin/gateway.json
5. 定义远程仓库
定义和管理github上的远程仓库。
$ git remote add iomssimu https://github.com/solarkai/IomsSimu.git
$ git remote
iomssimu
$ git remote get-url iomssimu
https://github.com/solarkai/IomsSimu.git
$ git remote set-url iomssimu https://github.com/solarkai/IomsSimu.git
6. 修改目录名称
修改原目录名称“reportFrontend”为“reportMicrogateway”。
$ git mv -f reportFrontend reportMicrogateway
$ git commit -m "change reportFrontend 2 reportMicrogateway"
[master 9341f77] change reportFrontend 2 reportMicrogateway
7. 提交到远程仓库
$ git push iomssimu master
Fatal: HttpRequestException encountered.
Username for 'https://github.com': solarkai
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 274 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/solarkai/IomsSimu.git
a12f1eb..9341f77 master -> master