git实战项目练习
1、Git 全局设置:
·你的目录· $ git config --global user.name "小青龙"
·你的目录· $ git config --global user.email "2377475674@qq.com"
2、创建 git 仓库
·你的目录· $ git init
Initialized empty Git repository in D:/aa_目前所做之事/uniapp组件库/u助校园v1/.git/
3、查看当前文件夹下的 文件的状态
命令:git status
·你的目录· (master)$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.hbuilderx/
App.vue
components/
index.html
main.js
manifest.json
node_modules/
package-lock.json
package.json
pages.json
pages/
static/
style/
uni.scss
uni_modules/
unpackage/
utils/
nothing added to commit but untracked files present (use "git add" to track)
4、将本地的文件添加到本地的工作区
命令: git add .
·你的目录· (master)$ git add .
·你的目录· (master)$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .hbuilderx/launch.json
new file: App.vue
new file: components/@lucky-canvas/uni/LICENSE
new file: components/@lucky-canvas/uni/README.md
new file: components/@lucky-canvas/uni/lucky-grid.vue
new file: components/@lucky-canvas/uni/lucky-wheel.vue
new file: components/@lucky-canvas/uni/package.json
.
.
.
这些全是你没有提交的文件
上述,将本地文件添加到了本地的工作区
5、提交文件到本地仓库
命令:git commit -m “注释(用来记录本次提交的内容-标识)”
·你的目录· 1 (master)$ git commit -m "第一次提交代码"
[master (root-commit) b1cd058] 第一次提交代码
748 files changed, 141533 insertions(+)
create mode 100644 .hbuilderx/launch.json
create mode 100644 App.vue
create mode 100644 components/@lucky-canvas/uni/LICENSE
create mode 100644 components/@lucky-canvas/uni/README.md
create mode 100644 components/@lucky-canvas/uni/lucky-grid.vue
create mode 100644 components/@lucky-canvas/uni/lucky-wheel.vue
create mode 100644 components/@lucky-canvas/uni/package.json
.
.
.
上述,就是将本地工作区中的代码,推送到本地的仓库
6、添加码云上的仓库
命令:git remote add origin xxx xxx是你的远程仓库地址
·你的目录· (master)$ git remote add origin https://gitee.com/auzredragonz/uchelper_f.git
7、将本地仓库的代码,推送到远程仓库(gitee上的仓库)
命令:git push -u origin “master”
命令解释:该命令是将本地仓库的代码,推送到远程仓库的master分支(该分支,是gitee默认的仓库分支)
·你的目录· (master)$ git push -u origin "master"
报错:
·你的目录· (master)$ git push -u origin "master"
To https://gitee.com/auzredragonz/uchelper_f.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/auzredragonz/uchelper_f.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.`
解决方法:
·你的目录· (master)$ git pull --rebase origin master
From https://gitee.com/auzredragonz/uchelper_f
* branch master -> FETCH_HEAD
Successfully rebased and updated refs/heads/master.
再次推送
·你的目录· (master)$ git push -u origin "master"
Enumerating objects: 1004, done.
Counting objects: 100% (1004/1004), done.
Delta compression using up to 8 threads
Compressing objects: 100% (823/823), done.
Writing objects: 100% (1003/1003), 2.18 MiB | 718.00 KiB/s, done.
Total 1003 (delta 179), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (179/179), done.
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/auzredragonz/uchelper_f.git
c691451..56132bf master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
8、查看本地的分支
命令:git branch
·你的目录· (master)
$ git branch
* master
post
带 * 的分支就是当前的分支
如上面的* master
表示当前的分支就是master
9、切换当前的分支到另外一个分支
命令:git checkout post
命令解释:切换当前分支 到 post分支
·你的目录· (master)
$ git checkout post
Switched to branch 'post'