作者:禅城花市C077 | 来源:互联网 | 2023-09-24 17:21
去年暑假接触到的git,由于之后不经常使用,渐渐变得陌生了,今日使用起来git感觉还是有点吃力,所以就总结下,以方便自己日后的查找,也方便别人学习。1、要想使用github,首先你
去年暑假接触到的git,由于之后不经常使用,渐渐变得陌生了,今日使用起来git感觉还是有点吃力,所以就总结下,以方便自己日后的查找,也方便别人学习。
1、要想使用github,首先你要有一个github账号,这样的话,才能把本地的代码上传到github服务器
2、建立本地的仓库
git init //建立本地仓库
touch readme.txt //创建一个文件
git add -A //添加要提交的文件,-A参数是添加所有的
git commit -m "this is note" //提交,引号中的是注释
这样一个本地仓库就创建完毕。
3、将本地的git仓库与github关联
要想将本地的git与github关联,首先要在本地创建key,并且把公钥添加到github中
生成key的命令,具体的效果见下图
$ git config --global user.name zhanghuijun-alite
$ git config --global user.email "1483386979@qq.com"
$ ssh-keygen -t rsa -C "1483386979@qq.com"
在“C:\Users\Administrator\.ssh”下生成了两个文件
把公钥文件用记事本打开,粘贴到github中的相应位置,到此为止,下面就可以愉快的上传代码了
使用的命令如下:
$ git remote add origin git@github.com:zhanghuijun0/demo-for-android.git #建立本地与远程关联
$ git pull origin master #更新代码到本地,如果省略这一步,会报错
$ git push -u origin master #提交代码到github
4、平时必用的git命令(由于这个是一个人操作,没有涉及到分支,及其其他情况)
$ git add -A
$ git commit -m "test1"
$ git pull origin master
$ git push -u origin master
5、下面是一个简单是示例, 首先在github上边有一个仓库,在本机新建一个仓库,创建了一个readme.txt文件,把readme.txt文件上传到github
上传前github的截图:
上传后github的截图:
操作步骤:
Administrator@lihuasheng MINGW64 ~/Desktop/demo
$ git init
Initialized empty Git repository in C:/Users/Administrator/Desktop/demo/.git/
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ touch readme.txt
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git add -A
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git commit -m "this is note"
[master (root-commit) 94d2d63] this is note
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme.txt
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git remote add origin git@github.com:zhanghuijun0/work.git
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git pull origin master
warning: no common commits
remote: Counting objects: 36, done.
remote: Total 36 (delta 0), reused 0 (delta 0), pack-reused 36
Unpacking objects: 100% (36/36), done.
From github.com:zhanghuijun0/work
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
Merge made by the 'recursive' strategy.
.classpath | 9 ++
.gitignore | 1 +
.project | 17 +++
.settings/org.eclipse.jdt.core.prefs | 11 ++
lib/json.jar | Bin 0 -> 94360 bytes
lib/jsoup-1.8.3.jar | Bin 0 -> 315321 bytes
lib/mysql-connector-java-5.1.22-bin.jar | Bin 0 -> 832960 bytes
log2015-10-17.log | 9 ++
log20151017.log | 1 +
mysql.conf | 4 +
src/com/zhj/tool/CommandHelper.java | 46 ++++++
src/com/zhj/tool/Connect.java | 82 ++++++++++
src/com/zhj/tool/CreateFolderHelper.java | 51 +++++++
src/com/zhj/tool/FolderHelper.java | 11 ++
src/com/zhj/tool/JsonHelper.java | 77 ++++++++++
src/com/zhj/tool/RCommandHelper.java | 42 +++++
src/com/zhj/tool/Sleep.java | 24 +++
src/com/zhj/tool/SqlHelper.java | 254 +++++++++++++++++++++++++++++++
src/com/zhj/tool/TestTimer.java | 46 ++++++
src/com/zhj/tool/TimeHelper.java | 128 ++++++++++++++++
src/com/zhj/tool/WriteFileHelper.java | 56 +++++++
21 files changed, 869 insertions(+)
create mode 100644 .classpath
create mode 100644 .gitignore
create mode 100644 .project
create mode 100644 .settings/org.eclipse.jdt.core.prefs
create mode 100644 lib/json.jar
create mode 100644 lib/jsoup-1.8.3.jar
create mode 100644 lib/mysql-connector-java-5.1.22-bin.jar
create mode 100644 log2015-10-17.log
create mode 100644 log20151017.log
create mode 100644 mysql.conf
create mode 100644 src/com/zhj/tool/CommandHelper.java
create mode 100644 src/com/zhj/tool/Connect.java
create mode 100644 src/com/zhj/tool/CreateFolderHelper.java
create mode 100644 src/com/zhj/tool/FolderHelper.java
create mode 100644 src/com/zhj/tool/JsonHelper.java
create mode 100644 src/com/zhj/tool/RCommandHelper.java
create mode 100644 src/com/zhj/tool/Sleep.java
create mode 100644 src/com/zhj/tool/SqlHelper.java
create mode 100644 src/com/zhj/tool/TestTimer.java
create mode 100644 src/com/zhj/tool/TimeHelper.java
create mode 100644 src/com/zhj/tool/WriteFileHelper.java
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git push -u origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 514 bytes | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
To git@github.com:zhanghuijun0/work.git
a825e20..89dc692 master -> master
Branch master set up to track remote branch master from origin.
Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$
View Code