編程隨筆(知識收納)-git常用命令示例
阿新 • • 發佈:2018-08-16
reset 圖形 delete ins htm git常用命令 ads 顯示 leaves 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
編程隨筆(知識收納)-git常用命令示例