git实战项目练习

本文详细介绍了使用Git进行项目管理的一系列步骤,包括设置用户信息、初始化仓库、查看文件状态、添加文件到工作区、提交到本地仓库、关联码云远程仓库并推送代码。在过程中遇到的推送冲突问题,也通过拉取并重新推送解决了。
摘要由CSDN通过智能技术生成

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'

10、继续努力

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

loongloongz

相互鼓励,相互帮助,共同进步。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值