Total Pageviews

Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

2015/04/02

[Git] Conflict Resolution

Problem

It's our source delivery process. 
After code review, we will merge branch into master


Unfortunately, if multiple programmers edit the same source code, it may occur conflicts. Hence, GitLab cannot merge automatically.


Solution
Step 1. After do Team => Merge, it will show you conflict list


Step 2.Do Team => Synchronize workspace => right click => Merge Tool

























Step3. Start do edit the conflicts

Step4. right click => Mark as Merged

Step 5. Commit and again

Step 6. After resolved conflict source codes and commit and push to Git. You can see the merge request can be merged into master now.


2015/03/27

[Git Tool] SourceTree

Requirement
目前專案採用 Git 作為程式碼管理工具,外包廠商的程式交付流程如下

由上圖可以看到,每次開發功能都要 create 一個 branch,完成後 commit上Git,並在GitLab create merge request。經過 review 後,此 branch 才可以 Merge 到 master。

如果我想要看到每次交付的branch,異動到的程式清單,以及每隻程式的異動內容的話,有什麼工具可以輔助達成此需求


Solution
SourceTree 是 Git 的 GUI 工具,讓你不需要用 command line,讓你可以將時間專注於程式開發上。

假設你在電腦中已經有一個 git folder,打開已經安裝好的SourceTree

1. File => Open


2. 指向 folder


3. Click OK


完成以上動作後,在左手邊可以看到現有的branch,假設我點選master,中間的地方就是commit的歷史紀錄



例如目前專案有不同廠商開發,點選某廠商最近commit的branch,中間就是此branch所增加、減少、修改的程式清單,點選某隻程式,右手邊就是該程式所修改的內容。藉此工具可以了解廠商本次commit的branch改了那些程式,動到哪些地方



Reference
[1] http://kenlai.logdown.com/posts/52372--git-dropbox-sourcetree-source-code-management
[2] http://www.sourcetreeapp.com/
[3] http://blog.lyhdev.com/2011/10/sourcetree-git-mercurial-gui-for-mac-os.html
[4] http://www.takobear.tw/201702608526356260322804024687/bear-git-flow-sourcetreegit-flow

2015/01/08

How to get changes from master into branch via egit

Question
 I am working in getDebtSpaceData branch.















Assume the DebtTypeEnum had been updated in master branch
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gov.nta.dbm.enumeration;

// TODO: Auto-generated Javadoc
/**
 * The Enum DebtTypeEnum.
 */
public enum DebtTypeEnum {

    /** The a. */
    A("A", "公債"),
    /** The b. */
    B("B", "國庫券"),
    /** The c. */
    C("C", "中長借"),
    /** The d. */
    D("D", "短借");

    private String code;
    private String name;

    private DebtTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * Gets the code.
     * 
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * Gets the name.
     * 
     * @return the name
     */
    public String getName() {
        return name;
    }

}

Therefore, the DebtTypeEnum in getDebtSpaceData branch is out-of-date.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gov.nta.dbm.enumeration;

// TODO: Auto-generated Javadoc
/**
 * The Enum DebtTypeEnum.
 */
public enum DebtTypeEnum {

    /** The a. */
    A("A", "公債"),
    /** The b. */
    B("B", ""),
    /** The c. */
    C("C", ""),
    /** The d. */
    D("D", "");

    private String code;
    private String name;

    private DebtTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * Gets the code.
     * 
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * Gets the name.
     * 
     * @return the name
     */
    public String getName() {
        return name;
    }

}

If I would like to pull up-to-date code from master branch and merge into getDebtSpaceData branch. How to do this?

Answer
Step1. Right click => Team => Merge
 Step2. Choose Master => Merge


Step3. Click OK


In getDebtSpaceData branch, we can see the content of DebtTypeEnum is up-to-date.

Reference

2014/12/19

How to delete a branch in EGit?

Question
Assume I created a branch, DBM_CommonService_getPaymentData, to implement a new function. 

After I finished this function and commit & push to GitLab,  and GitLab project owner merged this branch into master. 

If I had switch to master and would like to delete DBM_CommonService_getPaymentData branch, how to delete it?


Answer

Step1. right click => Team => Advanced => Delete branch

Step2. Selected the branch name you want to delete => Click "OK"

See..as you right click => Team => Switch to, you won't see DBM_CommonService_getPaymentData branch anymore.

Reference

2014/12/15

How to revert changes in EGit

Assume I have a form bean in gov.nta.dbm.web.dto

The form bean is as following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package gov.nta.dbm.web.dto;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

import lombok.Data;

@Data
public class Dbm915rFormBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int year = 0;
    private int month = 0;
    
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

If I add one more attribute in this form bean:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package gov.nta.dbm.web.dto;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

import lombok.Data;

@Data
public class Dbm915rFormBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int year = 0;
    private int month = 0;
    private String type;
    
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}

We can see this form bean had been modified and add ">" icon before file name to remind us this file had been modified.

If I would like to revert its changes, just right click => Replace with => HEAD Revision

Click OK to make sure to discard changes.

We can see the ">" label is disappeared.

And the form bean had been revert to original version:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package gov.nta.dbm.web.dto;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;

import lombok.Data;

@Data
public class Dbm915rFormBean implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int year = 0;
    private int month = 0;
    
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}


If you find out your revert action is success, but the ">" label still show in Eclipse.
Its EGit bug, go to its website ( http://eclipse.org/egit/download/ ) to update your EGit version.

2014/12/11

Checkout remote Git branch

Owing to our software development had been outsourced, here is the delivery process as function completion: 



As outsourced programmer completed his/her own function, he/she need to go to Gitlab to create a merge request to remind us:



Then we need to checkout his/her branch which he/she pushed to do code review.


Assume our initial branch is master, then there is the process to check out remote Git branch:



  • 1. Team => Remote => Fetch From...


  • 2. Click "Next"
  • 3. You can find out the branch name in merge request no matter in Gitlab or email. Hence, configure the source and destination ref. And click "Finish" button.

  •  4. Click OK


  • 5. Team => Switch To => Other..


  • 6. Remote Tracking => select specific branch name => Checkout.


  • 7. Checkout


  • 8. Click "Finish"


  • 9. We had changed from master to "DBM915R_new_function"







2014/11/21

2014/11/12

What's the difference between 'commit' and 'commit and push' in Git?

When I want to commit changes into git repository, I see two options to commit. One is "Commit", another one is "Commit and Push".

Here has a clear picture
If you do git commit, it means you only commit changes into your local repository.
If you do git push, it means you will commit changes to remote repository.


Demo
If I click Commit

Remote repository does not know what happened.



 If I click "Commit and Push"

Remote repository received these changes.

Reference
[1] http://stackoverflow.com/questions/2745076/what-are-the-differences-between-git-commit-and-git-push

2014/11/11

How to create project in GitLab and import project into Eclipse

Go to GitLab to create my project
1. Click New Project
 2. Fill in your project name, namespace => Create project


Open Git Bash
1. Change directory to my specific dirctory => make dbm directory => Initialized empty Git repository
1:  albert@ALBERT-PC ~  
2:  $ cd d:  
3:  albert@ALBERT-PC /d  
4:  $ cd git  
5:  albert@ALBERT-PC /d/git  
6:  $ mkdir dbm  
7:  albert@ALBERT-PC /d/git  
8:  $ cd dbm  
9:  albert@ALBERT-PC /d/git/dbm  
10:  $ git init  
11:  Initialized empty Git repository in d:/git/dbm/.git/  

2. create README file => add README to track => commit
1:  albert@ALBERT-PC /d/git/dbm (master)  
2:  $ touch README  
3:  albert@ALBERT-PC /d/git/dbm (master)  
4:  $ git add README  
5:  albert@ALBERT-PC /d/git/dbm (master)  
6:  $ git commit -m "first commit"  
7:  [master (root-commit) b45a8a4] first commit  
8:   1 file changed, 0 insertions(+), 0 deletions(-)  
9:   create mode 100644 README  

3. add git remote repository => push to remote
1:  albert@ALBERT-PC /d/git/dbm (master)  
2:  $ git remote add origin http://192.168.31.166/ifmis/dbm.git  
3:  albert@ALBERT-PC /d/git/dbm (master)  
4:  $ git push -u origin master  
5:  Username for 'http://192.168.31.166': albert_kuo  
6:  Password for 'http://albert_kuo@192.168.31.166':  
7:  Counting objects: 3, done.  
8:  Writing objects: 100% (3/3), 206 bytes | 0 bytes/s, done.  
9:  Total 3 (delta 0), reused 0 (delta 0)  
10:  To http://192.168.31.166/ifmis/dbm.git  
11:   * [new branch]   master -> master  
12:  Branch master set up to track remote branch master from origin.  

README file had been commit into git

Assume I create my project skeleton into my git folder

Add all files into track => commit => push to remote
1:  albert@ALBERT-PC /d/git/dbm (master)  
2:  $ git add .  
3:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/jasperreports/README.md.  
4:  The file will have its original line endings in your working directory.  
5:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/webapp/WEB-INF/templates/README.md.  
6:  The file will have its original line endings in your working directory.  
7:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/webapp/scripts/README.md.  
8:  The file will have its original line endings in your working directory.  
9:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/webapp/styles/README.md.  
10:  The file will have its original line endings in your working directory.  
11:  warning: LF will be replaced by CRLF in dbm-webapp/src/test/database/README.md.  
12:  The file will have its original line endings in your working directory.  
13:  warning: LF will be replaced by CRLF in dbm-webapp/src/test/database/test-datasource.xml.template-or  
14:  acle.  
15:  The file will have its original line endings in your working directory.  
16:  warning: LF will be replaced by CRLF in dbm-webapp/src/test/database/test-datasource.xml.template-sq  
17:  lserver.  
18:  The file will have its original line endings in your working directory.  
19:  warning: LF will be replaced by CRLF in pom.xml.  
20:  The file will have its original line endings in your working directory.  
21:  albert@ALBERT-PC /d/git/dbm (master)  
22:  $ git commit -m "create project skeleton"  
23:  [master 4abf50e] create project skeleton  
24:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/jasperreports/README.md.  
25:  The file will have its original line endings in your working directory.  
26:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/webapp/WEB-INF/templates/README.md.  
27:  The file will have its original line endings in your working directory.  
28:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/webapp/scripts/README.md.  
29:  The file will have its original line endings in your working directory.  
30:  warning: LF will be replaced by CRLF in dbm-webapp/src/main/webapp/styles/README.md.  
31:  The file will have its original line endings in your working directory.  
32:  warning: LF will be replaced by CRLF in dbm-webapp/src/test/database/README.md.  
33:  The file will have its original line endings in your working directory.  
34:  warning: LF will be replaced by CRLF in dbm-webapp/src/test/database/test-datasource.xml.template-or  
35:  acle.  
36:  The file will have its original line endings in your working directory.  
37:  warning: LF will be replaced by CRLF in dbm-webapp/src/test/database/test-datasource.xml.template-sq  
38:  lserver.  
39:  The file will have its original line endings in your working directory.  
40:  warning: LF will be replaced by CRLF in pom.xml.  
41:  The file will have its original line endings in your working directory.  
42:   22 files changed, 498 insertions(+)  
43:   create mode 100644 README.md  
44:   create mode 100644 dbm-entity/pom.xml  
45:   create mode 100644 dbm-entity/src/main/java/gov/nta/entity/package-info.java  
46:   create mode 100644 dbm-service/pom.xml  
47:   create mode 100644 dbm-service/src/main/java/gov/nta/dbm/repository/package-info.java  
48:   create mode 100644 dbm-service/src/main/java/gov/nta/dbm/service/package-info.java  
49:   create mode 100644 dbm-webapp/pom.xml  
50:   create mode 100644 dbm-webapp/src/main/jasperreports/README.md  
51:   create mode 100644 dbm-webapp/src/main/java/gov/nta/dbm/web/controller/package-info.java  
52:   create mode 100644 dbm-webapp/src/main/java/gov/nta/dbm/web/dto/package-info.java  
53:   create mode 100644 dbm-webapp/src/main/java/gov/nta/dbm/web/rest/package-info.java  
54:   create mode 100644 dbm-webapp/src/main/resources/gov/nta/dbm/Messages.properties  
55:   create mode 100644 dbm-webapp/src/main/webapp/WEB-INF/jboss-deployment-structure.xml  
56:   create mode 100644 dbm-webapp/src/main/webapp/WEB-INF/jboss-web.xml  
57:   create mode 100644 dbm-webapp/src/main/webapp/WEB-INF/templates/README.md  
58:   create mode 100644 dbm-webapp/src/main/webapp/WEB-INF/web.xml  
59:   create mode 100644 dbm-webapp/src/main/webapp/scripts/README.md  
60:   create mode 100644 dbm-webapp/src/main/webapp/styles/README.md  
61:   create mode 100644 dbm-webapp/src/test/database/README.md  
62:   create mode 100644 dbm-webapp/src/test/database/test-datasource.xml.template-oracle  
63:   create mode 100644 dbm-webapp/src/test/database/test-datasource.xml.template-sqlserver  
64:   create mode 100644 pom.xml  
65:  albert@ALBERT-PC /d/git/dbm (master)  
66:  $ git push -u origin master  
67:  Username for 'http://192.168.31.166': albert_kuo  
68:  Password for 'http://albert_kuo@192.168.31.166':  
69:  Counting objects: 64, done.  
70:  Delta compression using up to 4 threads.  
71:  Compressing objects: 100% (34/34), done.  
72:  Writing objects: 100% (63/63), 10.12 KiB | 0 bytes/s, done.  
73:  Total 63 (delta 2), reused 0 (delta 0)  
74:  To http://192.168.31.166/ifmis/dbm.git  
75:    b45a8a4..4abf50e master -> master  
76:  Branch master set up to track remote branch master from origin.

See..my project skeleton had been commit

Import Git project into Eclipse
1. Copy url

2. File => Import => choose SCM type to "git" => paste url => Finish

3. Well done.