1.4、GIT命令-上传下载新工程

1、GIT命令-上传下载新工程

新入一个项目,最先遇到也是最常见的两个场景:
若工程不存在,需要先创建一个工程,然后上传到git;
若git上已有工程,则下载工程。

1.1、使用Git命令上传新工程

1.1.1、新建工程

在这里插入图片描述

1.1.2、新建git仓库

方法步骤不详述了。

1.1.3、方式一:git初始化(init)

1.1.3.1、初始化文件夹

新建文件夹;在文件夹内右键,点击Git Bash Here,进入命令行,或在命令行,cd进入该文件夹;执行克隆:git init

$ git init
Initialized empty Git repository in C:/zyl_workspace/git_localresposisty/gitstudy20191011_2/.git/

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)

此时文件夹内出现一个隐藏文件.git
在这里插入图片描述

1.1.3.2、关联远程git仓库
$ git remote add origin https://github.com/ds0907/gitstudy20191011.git

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)
1.1.3.3、拉取文件

要先拉取文件,否则会有本地仓库与git远程仓库不一致等问题。

$ git pull origin master
From https://github.com/ds0907/gitstudy20191011
 * branch            master     -> FETCH_HEAD

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)

可以考到文件夹里已经有了几个文件,这是git仓库原本就有的文件。
在这里插入图片描述

1.1.3.4、add文件

将工程代码拷贝到此文件夹。
在这里插入图片描述
git add命令是将文件加入了index,可以理解为变更列表中。

$ git add .

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   git_java_demo/.classpath
        new file:   git_java_demo/.project
        new file:   git_java_demo/.settings/org.eclipse.jdt.core.prefs
        new file:   git_java_demo/bin/com/ds/demo/git/test/TestGit.class
        new file:   git_java_demo/src/com/ds/demo/git/test/TestGit.java

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)
1.1.3.5、commit文件

git commit两个作用,一个是增加注释,表明此次提交的原因,另一个就是将代码提交到本地仓库,为push做准备。

$ git commit -m "push first demo project"
[master 5611cb6] push first demo project
 5 files changed, 48 insertions(+)
 create mode 100644 git_java_demo/.classpath
 create mode 100644 git_java_demo/.project
 create mode 100644 git_java_demo/.settings/org.eclipse.jdt.core.prefs
 create mode 100644 git_java_demo/bin/com/ds/demo/git/test/TestGit.class
 create mode 100644 git_java_demo/src/com/ds/demo/git/test/TestGit.java

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)
1.1.3.6、push文件

git push将代码提交到远程git仓库中。

$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 271 bytes | 135.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To https://github.com/ds0907/gitstudy20191011.git
   7957332..995e341  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_2 (master)

在这里插入图片描述

1.1.4、方式二:git克隆(clone)

1.1.4.1、克隆
$ git clone https://github.com/ds0907/gitstudy20191011.git
Cloning into 'gitstudy20191011'...
remote: Enumerating objects: 35, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 35 (delta 4), reused 26 (delta 0), pack-reused 0
Unpacking objects: 100% (35/35), done.

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_4

可以看到这个文件夹下并无.git隐藏文件,但多了一个和仓库同名的文件夹,且文件夹内容与仓库中相同
在这里插入图片描述

1.1.4.2、add文件
$ git add .
fatal: not a git repository (or any of the parent directories): .git

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy201910
$ cd gitstudy20191011/

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_4/gitstudy20191011 (master)
$ git add .

yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_4/gitstudy20191011 (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   git_java_demo2/.classpath
        new file:   git_java_demo2/.project
        new file:   git_java_demo2/.settings/org.eclipse.jdt.core.prefs
        new file:   git_java_demo2/bin/com/ds/demo/git/test/TestGit.class
        new file:   git_java_demo2/src/com/ds/demo/git/test/TestGit.java
yunlzhan@LCN06370218 MINGW64 /c/zyl_workspace/git_localresposisty/gitstudy20191011_4/gitstudy20191011 (master)

第一次add文件,提示这不是一个git本地仓库。上一步也说了,本文件夹内务.git隐藏文件,但是下一级与仓库同名的文件夹内含有.git。所以我们要先进入这个下级文件夹。然后在git add

1.1.4.3、commit文件

同1.1.3.5、commit文件

$ git commit -m "push second demo project"
1.1.4.4、push文件

同1.1.3.6、push文件

$ git push -u origin master

1.2、使用Git命令下载新工程

同1.1.4、方式二:git克隆(clone),执行git clone即可下载远程文件到本地。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值