git項目管理

將本地項目經過git管理:linux

cd 項目路徑,執行:git

git initgithub

會在項目路徑下生成.git目錄,進入後 會看到新生成的文件和目錄:web

wangxiaodeMacBook-Pro:.git wangxiao$ lssql

HEAD config description hooks info objects refsapache

初使化的動做執行一次就能夠,若不想再經過git管理項目,直接刪除掉.git目錄就能夠了。服務器

linux操做系統下.文件夾不可見,可經過 open .git 打開文件夾了:eclipse

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git statusmaven

On branch masterfetch

 

Initial commit

 

Untracked files:

  (use "git add <file>..." to include in what will be committed)

 

.DS_Store

edu-common-config/

edu-common-core/

edu-common-parent/

edu-common-web/

edu-common/

edu-facade-user/

edu-service-user/

edu-web-boss/

"\345\210\235\345\247\213\345\214\226\350\204\232\346\234\254(MySQL).sql"

 

nothing added to commit but untracked files present (use "git add" to track)

接下來使用 git add 文件名來添加待提交的文件, git add . 表示添加全部待提交的文件

而後git status查看項目狀態

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git status

On branch master

 

Initial commit

 

Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

 

new file:   .DS_Store

new file:   edu-common-config/.DS_Store

new file:   edu-common-config/.classpath

new file:   edu-common-config/.project

new file:   edu-common-config/.settings/org.eclipse.core.resources.prefs

new file:   edu-common-config/.settings/org.eclipse.jdt.core.prefs

new file:   edu-common-config/.settings/org.eclipse.m2e.core.prefs

new file:   edu-common-config/.settings/org.eclipse.wst.common.component

 

使用 git commit -m '註釋' 提交代碼,註釋用來講明提交代碼的功能

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git commit -m 'Dubbo實踐項目'

[master (root-commit) 47a3011] Dubbo實踐項目

 951 files changed, 57796 insertions(+)

 create mode 100644 .DS_Store

 create mode 100644 edu-common-config/.DS_Store

 create mode 100644 edu-common-config/.classpath

 create mode 100644 edu-common-config/.project

 create mode 100644 edu-common-config/.settings/org.eclipse.core.resources.prefs

 create mode 100644 edu-common-config/.settings/org.eclipse.jdt.core.prefs

 create mode 100644 edu-common-config/.settings/org.eclipse.m2e.core.prefs

 create mode 100644 edu-common-config/.settings/org.eclipse.wst.common.component

 create mode 100644 edu-common-config/.settings/org.eclipse.wst.common.project.facet.core.xml

 create mode 100644 edu-common-config/pom.xml

這樣就完成了第一次的提交,如今工做目錄是乾乾淨的,沒有什麼可提交的。

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git status

On branch master

nothing to commit, working tree clean

git log查看提交版本和日誌

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git log

commit 47a30116aa22a39b114987b8b75cfd7c16a7aa9d

Author: 王曉 <wangxiao.xiw@gmail.com>

Date:   Tue Jun 27 16:23:18 2017 +0800

 

    Dubbo實踐項目

當咱們修改一個文件後,

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ 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:   edu-common-parent/pom.xml

 

no changes added to commit (use "git add" and/or "git commit -a")

咱們想查看一下文件修改前修改後的一個區別,能夠使用 git diff命令

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git diff 

diff --git a/edu-common-parent/pom.xml b/edu-common-parent/pom.xml

index e1f5f86..d344254 100755

--- a/edu-common-parent/pom.xml

+++ b/edu-common-parent/pom.xml

@@ -10,12 +10,6 @@

        <name>edu-common-parent</name>

        <url>http://maven.apache.org</url>

 

-       <!-- <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus 

-               Release Repository</name> <url>http://192.168.100.66:8081/nexus/content/repositories/releases/</url> 

-               </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot 

-               Repository</name> <url>http://192.168.100.66:8081/nexus/content/repositories/snapshots/</url> 

-               </snapshotRepository> </distributionManagement> -->

-

        <properties>

                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

對於git來講是一行一行對比的,能夠看到咱們刪除了幾行註釋,下面使用git add 添加修改。

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git add .

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git commit -m '刪除pom無效註釋' 

[master d9dee74] 刪除pom無效註釋

 1 file changed, 6 deletions(-)

 

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git status

On branch master

nothing to commit, working tree clean

 

遠程

咱們能夠爲項目在遠程服務器上建立一個版本庫,再把本地推送到遠程,好處是本地版本整丟了,能夠去遠程恢復,還能夠讓其它人協做開發。

咱們能夠使用github建立免費公共的版本庫,可是github國內訪問慢,咱們改用國內github碼雲git.oschina.net建立也是同樣的。

 

 

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git remote add origin https://git.oschina.net/xiw/edu-dubbo-demo.git

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git push -u origin master

To https://git.oschina.net/xiw/edu-dubbo-demo.git

 ! [rejected]        master -> master (fetch first)

error: failed to push some refs to 'https://git.oschina.net/xiw/edu-dubbo-demo.git'

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.

 

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git remote -v

origin https://git.oschina.net/xiw/edu-dubbo-demo.git (fetch)

origin https://git.oschina.net/xiw/edu-dubbo-demo.git (push)

push以前 須要先pull更新同步一把

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git pull --rebase origin 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://git.oschina.net/xiw/edu-dubbo-demo

 * branch            master     -> FETCH_HEAD

 * [new branch]      master     -> origin/master

First, rewinding head to replay your work on top of it...

Applying: Dubbo實踐項目

Applying: 刪除pom無效註釋

再同步代碼到遠程分支能正常了

wangxiaodeMacBook-Pro:基礎篇--第01節--使用Dubbo對傳統工程進行服務化改造的思路介紹--工程源碼 wangxiao$ git push -u origin master

Counting objects: 1106, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (922/922), done.

Writing objects:  96% (1062/1106), 27.77 MiB | 3.27 MiB/s

相關文章
相關標籤/搜索