命令(删除文件时)
- 1、git status/查看代码的修改状态
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: .mvn/wrapper/maven-wrapper.jar
deleted: .mvn/wrapper/maven-wrapper.properties
deleted: mvnw
deleted: mvnw.cmd
no changes added to commit (use "git add" and/or "git commit -a")
如果git status打印信息是changes to be committed(已暂存),则直接进入第2步;否则执行命令git rm 如下:
$ git rm .mvn/wrapper/maven-wrapper.jar
$ git rm .mvn/wrapper/maven-wrapper.properties
$ git rm mvnw
$ git rm mvnw.cmd
- 2、git commit/提交已暂存的文件
$ git commit
[master 569e27b] 删除mvnw等文件
4 files changed, 369 deletions(-)
delete mode 100644 .mvn/wrapper/maven-wrapper.jar
delete mode 100644 .mvn/wrapper/maven-wrapper.properties
delete mode 100644 mvnw
delete mode 100644 mvnw.cmd
- 3、git pull/先同步代码到本地
$ git pull
Already up-to-date.
- 4、git push origin <本地分支名>/再同步到服务器
$ git push origin master
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 253 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To git@github.com:xiayongchao/angularjs.git
ef893f7..569e27b master -> master
命令(修改文件内容时)
- 1、git status/查看代码的修改状态
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: src/main/java/com/xyc/redis/RedisApplication.java
no changes added to commit (use "git add" and/or "git commit -a")
- 2、git add /暂存需要提交的文件
$ git add src/main/java/com/xyc/redis/RedisApplication.java
warning: LF will be replaced by CRLF in src/main/java/com/xyc/redis/RedisApplication.java.
The file will have its original line endings in your working directory.
- 3、git commit/提交已暂存的文件
$ git commit
[master warning: LF will be replaced by CRLF in src/main/java/com/xyc/redis/RedisApplication.java.
The file will have its original line endings in your working directory.
13e60ac] 添加注释
warning: LF will be replaced by CRLF in src/main/java/com/xyc/redis/RedisApplication.java.
The file will have its original line endings in your working directory.
1 file changed, 11 insertions(+)
- 4、git pull/先同步代码到本地
$ git pull
Already up-to-date.
- 5、git push origin <本地分支名>/再同步到服务器
$ git push origin master
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 904 bytes | 0 bytes/s, done.
Total 9 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@github.com:xiayongchao/redis.git
a939a1e..13e60ac master -> master