一、前言
将本地项目推送到远程git管理的方法通常有两种做法。其一,先在git上创建仓库,本地直接拉取,但这种做法不方便之处项目是一个完全空白的项目,各种包依赖都要手动配置,影响工作效率。其二,在本地利用脚手架工具创建项目,后推送到远程仓库进行管理。下面我将简单记录如何推送本地项目到git。
二、操作
首先,在git上创建一个完全空白的仓库,不要选择生成license或者.gitignore等文件。然后依据以下步骤实现:
注意:推送代码时不要将.idea等文件推送到仓库。因为该类文件,其他项目成员clone该项目时会造成文件冲突。可以在.gitigonre文件设置不添加git管理的文件。文章最后,我会附上样文。
1)初始化仓库
F:\ldm-IDEA\flow-util>git init
Initialized empty Git repository in F:/ldm-IDEA/flow-util/.git/
2)暂存变更
F:\ldm-IDEA\flow-util>git add .
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory.
3)查看工作区和暂存状态
F:\ldm-IDEA\flow-util>git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: README.md
new file: flow-util-business/pom.xml
4)提交变更
F:\ldm-IDEA\flow-util>git commit -m 'init'
[master (root-commit) 5fe84ce] 'init'
101 files changed, 9905 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 flow-util-business/pom.xml
5)查看提交历史
F:\ldm-IDEA\flow-util>git log
WARNING: terminal is not fully functional
commit 5fe84ce7f2fa106dfec882bf7ceb30bcca225bd7
Author: lindm
Date: Thu Nov 29 17:34:28 2018 +0800
'init'
6)增加新的远程仓库
F:\ldm-IDEA\flow-util>git remote add origin git@xxx/flow-util.git(仓库地址)
7)列出远程分支的详细信息
F:\ldm-IDEA\flow-util>git remote -v
origin git@xxx/flow-util.git (fetch)
origin git@xxx/flow-util.git (push)
8)推送到远程仓库origin的master分支
F:\ldm-IDEA\flow-util>git push -u origin master
Counting objects: 155, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (127/127), done.
Writing objects: 100% (155/155), 74.12 KiB | 0 bytes/s, done.
Total 155 (delta 36), reused 0 (delta 0)
remote: 处理 delta 中: 100% (36/36), 完成.
To rjgit:xxx/flow-util.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
三、.gitignore文件设置
# Maven
target/
log/
*.iml
.idea/
# ---> Java
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# ---> Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
网友评论