Total Pageviews

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

2021/12/19

[Git] 執行 git add --all 出現 warning: CRLF will be replaced by LF in ...

Problem

當我執行 git add -all 時,出現以下警告訊息

warning: CRLF will be replaced by LF in XXX

The file will have its original line endings in your working directory.


 How-To

執行以下指令,即可解決上述 warning 訊息

git config --global core.autocrlf true
git config --global core.safecrlf true


2021/12/12

[Git] 無法正常顯示中文檔名

Problem

在 Mac 環境下,執行以下指令時,無法正常顯示繁體中文檔名

Untracked files:

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



	"Power BI\345\205\245\351\226\200 \345\244\247\346\225\270\346\223\232\350\246\226\350\246\272\345\214\226 + \346\231\272\346\205\247\346\261\272\347\255\226 + \351\233\262\347\253\257\345\210\206\344\272\253/my practice/ch6/"


How-To

執行以下指令進行設定

git config --global core.quotePath false


即可正常顯示繁體中文檔名

Untracked files:

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



	Power BI入門 大數據視覺化 + 智慧決策 + 雲端分享/my practice/ch6/


Reference

[1] https://stackoverflow.com/a/34549249

2019/01/10

[Git] How to revert multiple git commits?

Problem
Here is my commit history:

If I would like to revert to B, how to do it?


How-To
Git commands:
git reset --hard B
git reset --mixed E
git commit



Reference
[1] https://stackoverflow.com/questions/1463340/how-to-revert-multiple-git-commits/1463390#1463390

2018/07/07

[Git] How to remove directory from git repository?

Problem
I had committed and pushed target folder to git repository by accident. How to remove it?



How-To
You can remove target folder by the following process:




Here has the result after removing target folder




2018/06/06

[Git] How to resolve non-fast-forward problem?

Problem
As I try to push my branch to GitLab
git push origin fix_issue6


I get this error message when I do push:
To https://gitlab.com/xxx/xxx.git
 ! [rejected]        fix_issue6 -> fix_issue6 (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/xxx/xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.



How-To
Here has the resolution process:

2018/01/09

[GitLab] How to build jar file automatically

Problem
If I hope GitLab can build a jar file when I commit source code, how to do it?
I am using Maven 3.3.3 and JDK 7 in eclipse, and using mvn clean install -Dmaven.test.skip=true to build WAR file in eclipse.

How-To

Step 1. Add .gitlab-ci.yml to the root directory of my project, the content looks like:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
image: maven:3.3.3-jdk-7
    
build:
  stage: build
  script:
   - "mvn clean install -Dmaven.test.skip=true"
  artifacts:
    expire_in: 1 week
    when: on_success
    paths:
    - target/*.jar

Step 2. Add, commit and push .gitlab-ci.yml to GitLab
Step 3. Seeing the status of your pipeline and jobs 


Reference

[1] https://docs.gitlab.com/ce/ci/quick_start/README.html

2018/01/08

[GitLab] How to build WAR file automatically

Problem
If I hope GitLab can build a WAR file when I commit source code, how to do it?
I am using Maven 3 and JDK 7 in eclipse, and using mvn clean package -U to build WAR file in eclipse.

How-To

Step 1. Add .gitlab-ci.yml to the root directory of my project, the content looks like: 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
image: maven:3-jdk-7

build:
  stage: build
  script: "mvn clean package -U"
  artifacts:
    expire_in: 1 week
    when: always
    paths:
    - target/*.war

Step 2. Add, commit and Push .gitlab-ci.yml to GitLab
Step 3. Seeing the status of your pipeline and jobs 

Reference

[1] https://docs.gitlab.com/ce/ci/quick_start/README.html
[2] https://hub.docker.com/r/library/maven/tags/

2018/01/06

[Git] fatal:LF would be replaced by CRLF

Problem
As I try to use the git add command adds a change in the working directory to the staging area, it show the error:
fatal: LF would be replaced by CRLF


Here has a post to solve this problem: https://albert-kuo.blogspot.tw/2016/12/git-fatal-lf-would-be-replaced-by-crlf.html

But if I have hundreds of file have this problem, how to solve this problem?


Solution

Step 1. download file from http://www.bastet.com/uddu.zip

Step 2. Unzip and copy UNIX2DOS.EXE and UNIX2DOS.C to the root directory of your project.


Step 3. Assign the file extension you would like to do replacement in the command and execute this command:

for /f %f IN ( 'dir /b /s *.xml *.pom *.sha1' ) DO @unix2dos %f

Step 4. Remove  UNIX2DOS.EXE and UNIX2DOS.C from your project.

2017/02/03

[Git] Commit undo process

Problem
If we would like to clean up my commits, i.e. remove some unnecessary commits, how to do it?



How-to


If we would like to revert to this commit which number is ead950a


The commands are as bellows:


The result is as bellows:


2017/02/02

2016/12/03

[Git] fatal: LF would be replaced by CRLF

Problem
As I try to use the git add command adds a change in the working directory to the staging area. 

It show the fatal error message as bellows:
albert@albert-PC MINGW64 /d/git/ChromeExtensions (master)
$ git add --all
fatal: LF would be replaced by CRLF in HelloWorld/manifest.json



How-to
This fatal error message results from this command fail to pass crlf check.

Here has the solution to fix this file's crlf problem.
If you have Notepad++ installed in your computer, simply follow these steps.
[1] Open the file that is having the fatal issue.
[2] Click Edit -> EOL Conversion, then select Windows Format and save it.





2016/08/09

[Git] Frequently Used Command

1. how to show file change list?
 
 
 
 
 
 
 
 
 
albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 6 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   src/app/journal/journal.list.component.ts
        modified:   src/app/journal/journal.list.html


2. How to create a branch from master? (given your branch name after -b)

albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git checkout -b fix#165468
       src/app/journal/journal.list.component.ts
       src/app/journal/journal.list.html
Switched to a new branch 'fix#165468'


3. How to discard changes? (assign the file path after git checkout)

albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git checkout  src/app/journal/journal.list.component.ts


4. How to change from my local branch to master?


albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git checkout master


5. How to add all changed files and commit to local? (remember to add comments as you do commit)
albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git add --all

albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git commit -m 'fix #165468'
[fix#165468 dbec729] fix #165468
 2 files changed, 25 insertions(+), 5 deletions(-)


6. How to push commits made on your local branch to a remote repository? (assign your branch name after origin)
 albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git push origin fix#165468


7. How to synchronize my local repository with remote repository?
albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git pull --rebase upstream master
From https://github.com/ChunghwaTelecom/issue-webapp
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to b393bd26111dbe2335bf1fb5d9cf3cb110c278ca.


8. How to list values of all configuration? 

albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true


9. 
How to configure remote.upstream.url to https://gitlab.com/ChunghwaTelecom/rakr-chrome-extension.git ?
albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git config remote.upstream.url https://gitlab.com/ChunghwaTelecom/rakr-chrome-extension.git


10. Check commit history 
git log --pretty=oneline -10




2016/02/27

How to import a git non-Java project into Eclipse

Assume I import a non-Java project from GitHub into Eclipse

1. Import non-Java project from GitHub: File => Import


2. Choose Git => Projects from Git => Next


3. Select Git Repository => Click Next


4. Choose "Import as general project" => Click Next


5. Click Finish


Import project successfully !



Owing to the project which import from GitHub is non-Java project, so I would like to change it to Java Project.

1. Right click on this project => properties


2. Click Project Facelets = > Covert to faceted form


3. Check Java => Apply => click OK


4. Done !



2016/01/06

[Git] The requested URL returned error: 403

Problem
When I try to clone project from GitLab, it shows the following error message




How-To
Try to use SSH instead of HTTP, this annoying problem will be resolved.




But the root cause does not know yet.




2015/06/22

[egit] Fail to change branch from master to another

Problem
I want to change branch from master to another branch (i.e. WebcommUpload0618 )

But it failed to change branch via egit.
As I change branch again, but it show this error message:


The problem is there are some source belong to another branch but copy to master, because egit fail to do rollback. 

So it added some untracked files which belong to WebcommUpload0618 branch not master branch

Solution
1. use git status to list untracked files 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
albert@ALBERT-PC /D/git/dbm (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

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

        dbm-service/src/main/java/gov/nta/dbm/repository/Dbm091fbRepository.java
        dbm-service/src/main/java/gov/nta/dbm/repository/impl/Dbm091fbRepositoryImpl.java
        dbm-service/src/main/java/gov/nta/dbm/service/Dbm016rService.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData1Vo.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData2Vo.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData3Vo.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData4Vo.java

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

2. use git clean -n to list the files which will be removed
1
2
3
4
5
6
7
8
9
albert@ALBERT-PC /D/git/dbm (master)
$ git clean -n
Would remove dbm-service/src/main/java/gov/nta/dbm/repository/Dbm091fbRepository.java
Would remove dbm-service/src/main/java/gov/nta/dbm/repository/impl/Dbm091fbRepositoryImpl.java
Would remove dbm-service/src/main/java/gov/nta/dbm/service/Dbm016rService.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData1Vo.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData2Vo.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData3Vo.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData4Vo.java

3. use git clean -f to remove files
1
2
3
4
5
6
7
8
9
albert@ALBERT-PC /D/git/dbm (master)
$ git clean -f
Removing dbm-service/src/main/java/gov/nta/dbm/repository/Dbm091fbRepository.java
Removing dbm-service/src/main/java/gov/nta/dbm/repository/impl/Dbm091fbRepositoryImpl.java
Removing dbm-service/src/main/java/gov/nta/dbm/service/Dbm016rService.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData1Vo.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData2Vo.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData3Vo.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData4Vo.java

After cleaning untracking files, then I can change granch succesfully

Reference
[1] https://ihower.tw/git/basic.html

2015/06/01

[Git] Why is the egit merge tool disabled in Eclipse

Problem
After I create a merge request in GitLab, GitLab remind me this branch cannot be merged automatically.

As I open context menu from my project and try to resolve conflict issues, select Team --> Merge. But the menu option had been disabled.


Solution
1. Change to Git perspective. Branches => Remote Tracking => origin/master

2. Open context menu => Synchronize with Workspace

3. The conflict list is the source code which had been marked red.























4. Fix the foregoing conflict problems and open context menu => Marked as Merged

5. After fixed conflict problems, then push and commit to master again.