好久没用GIT,再次捡起来,遇到了些错误,比如没写comment,导致没提交成功,没有先从远程pull,导致没push成功。
于是将这个过程记录如下:
1:首先,跳转到项目根目录
2:查看当前状态
3:把我们要提交的文件的信息添加到索引库中
4: 提交文件到本地库
5:合并到远程代码库(首先要将远程库,pull到本地,否则不能push)
5.1:没有将远程库pull到本地,报错:
6:pull远程到本地
7:设置 git ignore 过滤文件,.class 后缀文件不提交到远程
8:再次push,成功
具体如下:
1:首先,跳转到项目根目录
Administrator@JS-PC /e/abc
$ cd CanYin-www
Administrator@JS-PC /e/abc/CanYin-www (master)
$ ls
LICENSE README.md pom.xml src target
2:查看当前状态
$ git status;
On branch 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/cn/canyin/dao/MenuDao.java
...
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/main/java/cn/canyin/dao/Dao.java
...
no changes added to commit (use "git add" and/or "git commit -a")
3: 把我们要提交的文件的信息添加到索引库中
Administrator@JS-PC /e/abc/CanYin-www (master)
$ git add .
4: 提交文件
Administrator@JS-PC /e/abc/CanYin-www (master)
$ git commit -a #注意这一步要写comment
[master dfce490] add menu model, changed by jonsanguo at 20140408
27 files changed, 546 insertions(+), 11 deletions(-)
create mode 100644 src/main/java/cn/canyin/dao/Dao.java
...
5:合并到远程代码库(首先要将远程库,pull到本地,否则不能push)
Administrator@JS-PC /e/abc/CanYin-www (master)
$ git push https://github.com/guojiangshan/canyin master
Username for 'https://github.com': guojiangshan
Password for 'https://guojiangshan@github.com':
Counting objects: 81, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (45/45), done.
Writing objects: 100% (49/49), 8.40 KiB | 0 bytes/s, done.
Total 49 (delta 16), reused 0 (delta 0)
To https://github.com/guojiangshan/canyin
66640ab..dfce490 master -> master
5.1:没有将远程库pull到本地,报错:
$ git push https://github.com/guojiangshan/canyin master
Username for 'https://github.com': guojiangshan
Password for 'https://guojiangshan@github.com':
To https://github.com/guojiangshan/canyin
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/guojiangshan/canyin'
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.
6:pull远程到本地
$ git pull https://github.com/guojiangshan/canyin master
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From https://github.com/guojiangshan/canyin
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
.gitignore | 11 ++
LICENSE | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
README.md | 4 +
3 files changed, 354 insertions(+)
create mode 100644 .gitignore
create mode 100644 LICENSE
create mode 100644 README.md
7:设置 git ignore 过滤文件,.class 后缀文件不提交到远程
$ echo *.class>.gitignore
查看设置是否成功:
$ cat .gitignore
*.class
8:再次push,成功
$ git push https://github.com/guojiangshan/canyin master
Username for 'https://github.com': guojiangshan
Password for 'https://guojiangshan@github.com':
Counting objects: 116, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (102/102), done.
Writing objects: 100% (115/115), 58.02 KiB | 0 bytes/s, done.
Total 115 (delta 6), reused 0 (delta 0)
To https://github.com/guojiangshan/canyin
f7ddeea..5fd03b6 master -> master