- 查看当前状态
git status
,查看当前哪些代码未提交,及文件修改状态yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git status On branch developer Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: .eslintrc.js modified: package.json modified: src/App.vue deleted: src/components/HelloWorld.vue modified: src/main.js modified: src/plugins/element.js modified: src/router/index.js deleted: src/views/About.vue deleted: src/views/Home.vue modified: yarn.lock Untracked files: (use "git add <file>..." to include in what will be committed) src/components/home.vue src/components/login.vue vue.config.js no changes added to commit (use "git add" and/or "git commit -a")
- 查看分支
git branch
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git branch * developer master
- 添加文件
git add .
,如果添加单个文件后面跟文件名,如果添加所有文件使用通配符.
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git add . yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git status On branch developer Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: .eslintrc.js modified: package.json modified: src/App.vue deleted: src/components/HelloWorld.vue new file: src/components/home.vue new file: src/components/login.vue modified: src/main.js modified: src/plugins/element.js modified: src/router/index.js deleted: src/views/About.vue deleted: src/views/Home.vue new file: vue.config.js modified: yarn.lock
- 提交文件
git commit -m 'xxxx'
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git commit -m 'login complete' [developer 7f226a9] login complete 13 files changed, 254 insertions(+), 155 deletions(-) rewrite src/App.vue (83%) delete mode 100644 src/components/HelloWorld.vue create mode 100644 src/components/home.vue create mode 100644 src/components/login.vue rewrite src/router/index.js (73%) delete mode 100644 src/views/About.vue delete mode 100644 src/views/Home.vue create mode 100644 vue.config.js
- 切换分支
git checkout xxx
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git checkout master Switched to branch 'master'
- 合并分支
git merge xxx
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git merge developer Updating 85c9d12..7f226a9 Fast-forward .eslintrc.js | 2 ++ package.json | 2 ++ src/App.vue | 29 +++++++---------------------- src/components/HelloWorld.vue | 59 ----------------------------------------------------------- src/components/home.vue | 12 ++++++++++++ src/components/login.vue | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.js | 4 +++- src/plugins/element.js | 7 +++++-- src/router/index.js | 36 +++++++++++++++++++----------------- src/views/About.vue | 5 ----- src/views/Home.vue | 18 ------------------ vue.config.js | 5 +++++ yarn.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 13 files changed, 229 insertions(+), 130 deletions(-) delete mode 100644 src/components/HelloWorld.vue create mode 100644 src/components/home.vue create mode 100644 src/components/login.vue delete mode 100644 src/views/About.vue delete mode 100644 src/views/Home.vue create mode 100644 vue.config.js
- 创建分支
git checkout -b xxx
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git checkout -b home Switched to a new branch 'home' yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git branch developer * home master
- 删除本地分支
git branch -d xxx
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git branch -d home Deleted branch home (was 7f226a9). yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git branch * developer master
- 设置远程代码仓库地址
git remote add origin https://xxx.xxx.xxx/xxx.git
git remote add origin https://e.coding.net/yusian/vue/shop.git
- 推送到远程指定分支
git push -u origin master
,如果已存在远程分支可省略参数-uyusian@Work-SianMac:~/Documents/Project/Vue/demo34% git push -u origin master Enumerating objects: 55, done. Counting objects: 100% (55/55), done. Delta compression using up to 4 threads Compressing objects: 100% (48/48), done. Writing objects: 100% (55/55), 125.72 KiB | 4.49 MiB/s, done. Total 55 (delta 14), reused 0 (delta 0) To https://e.coding.net/yusian/vue/shop.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'. yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git push Everything up-to-date
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git checkout developer Switched to branch 'developer' yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git push -u origin developer Total 0 (delta 0), reused 0 (delta 0) To https://e.coding.net/yusian/vue/shop.git * [new branch] developer -> developer Branch 'developer' set up to track remote branch 'developer' from 'origin'. yusian@Work-SianMac:~/Documents/Project/Vue/demo34%
- 修改本地分支
git branch -m old new
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git branch -m developer login yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git branch * login master user
- 修改远程分支 其实是删除原远程分支
git push --delete origin old
,再创建新分支git push -u origin new
yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git push --delete origin developer To https://e.coding.net/yusian/vue/shop.git - [deleted] developer yusian@Work-SianMac:~/Documents/Project/Vue/demo34% git push -u origin login Total 0 (delta 0), reused 0 (delta 0) To https://e.coding.net/yusian/vue/shop.git * [new branch] login -> login Branch 'login' set up to track remote branch 'login' from 'origin'.
git代码仓库常用命令集
Leave a reply