目录
本地仓库操作
一.基本信息设置
ls 查看当前文件
cd ~ 进入home目录
ls | grep community 查看所有关于community的文件
cd .. //返回上一级目录
pwd 查看当前文件路径
mkdir text 创建一个名为text的文件夹
touch a.cpp 创建一个名为a.cpp文件
cd text 进入text文件夹中
cat 查看文件内容
rm a.cpp 删除a.cpp文件
git log 查看操作日志
1.设置用户名
git config --global user.name '用户名'
2.设置用户邮箱
git config --global user.email '邮箱地址'
二.初始化一个新的Git仓库
1.在文件内初始化git(创建git仓库)
cd test
git init //会生成一个隐藏文件 .git
2.向仓库添加文件
使用touch a.cpp 创建一个名为a.cpp文件
将a.cpp添加到暂存区
git add a.cpp
git status //查看文件状态
3.添加描述内容,并将文件从暂存区提交到仓库
git commit -m '描述内容'
4.推送到远端
git push
三.分支开发模式
git branch branch1 //创建一个名为branch1的分支
git checkout branch1 //切换到branch1上
git status //查看状态
git add 文件名
git commit -m "描述"
git push
如果你在远端上没有branch1分支则使用:
git push --set-upstream origin branch1//不仅推送到远端,还创建branch1分支
git checkout -b branch2 //检出同时创建分支branch2
git status //查看状态
git add 文件名
git commit -m "描述"
如果你在远端上没有branch1分支则使用:
git push --set-upstream origin branch2//不仅推送到远端,还创建branch2分支
将分支branch1和branch2所完成的任务合并到master分支上
git checkout master //回到master分支
git pull //更新最新的代码到本地
git merge branch1 //将branch1中的内容更新到master中
git push
四.windows下使用idea提交代码到github
cd .. //返回上一级目录
cd 目录名 //进入某个目录
dir //查看当前文件夹下所有目录
4.1 初始化
D:\community>git init
Initialized empty Git repository in D:/community/.git/
4.2查看状态
D:\community>git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
.mvn/
mvnw
mvnw.cmd
pom.xml
src/
nothing added to commit but untracked files present (use "git add" to track)
4.3 将当前目录下所有的文件加入暂存区
D:\community>git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/MavenWrapperDownloader.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/maven-wrapper.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.cmd.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/java/cn/zh/community/CommunityApplication.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/resources/application.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/test/java/cn/zh/community/CommunityApplicationTests.java.
The file will have its original line endings in your working directory.
4.4 将暂存区的文件提交到本地文件
D:\community>git commit -m "init repo"
[master (root-commit) ec2784b] init repo
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/MavenWrapperDownloader.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/maven-wrapper.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.cmd.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/java/cn/zh/community/CommunityApplication.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/resources/application.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/test/java/cn/zh/community/CommunityApplicationTests.java.
The file will have its original line endings in your working directory.
12 files changed, 704 insertions(+)
create mode 100644 .gitignore
create mode 100644 .mvn/wrapper/MavenWrapperDownloader.java
create mode 100644 .mvn/wrapper/maven-wrapper.jar
create mode 100644 .mvn/wrapper/maven-wrapper.properties
create mode 100644 mvnw
create mode 100644 mvnw.cmd
create mode 100644 pom.xml
create mode 100644 src/main/java/cn/zh/community/CommunityApplication.java
create mode 100644 src/main/java/cn/zh/community/controller/HelloController.java
create mode 100644 src/main/resources/application.properties
create mode 100644 src/main/resources/templates/hello.html
create mode 100644 src/test/java/cn/zh/community/CommunityApplicationTests.java
4.5 将本地文件提交到远端
D:\community\.git>git remote add origin git@github.com:zhgetyou/community.git
D:\community\.git>git push -u origin master
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Counting objects: 30, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (30/30), 50.29 KiB | 0 bytes/s, done.
Total 30 (delta 0), reused 0 (delta 0)
To git@github.com:zhgetyou/community.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
4.6如有是对已经提交的文件修改后再次提交可使用如下:
D:\community>git commit --amend --no-edit
[master 4c38ab2] add readme
Date: Mon Oct 7 15:59:09 2019 +0800
1 file changed, 12 insertions(+)
create mode 100644 README.md
4.7当远端的代码被改过了
使用:git pull
ESC Shift :X 保存退出