반응형

현재 브랜치와 다른 브랜치 사이에 merge가 아닌 특정 파일만 합치고 싶을때의 방법이다. 

 

git -p [브랜치명] -- [파일경로]

 

브랜치명 : 합쳐야 하는 내용들이 있는 브랜치 명을 입력하면 된다. (현재 브랜치가 아님)

파일경로 : 파일 path 를 넣으면 된다.

 

파일 경로 입력할때 다음과 같이 찾아보면 편리하다.

 

git diff --name-status [브랜치명]

 

이렇게 하면 현재 브랜치와 [브랜치명]에 있는 브랜치의 다른점 목록이 나온다. 

이 경로로 입력을 하면 된다. 

 

 

728x90
반응형
반응형

Virtual Box 에서 VM 을 띄우다 보면 화면의 해상도가 작을 때가 있다. 그래서 사용하기 상당히 불편한데 이것은 확장 패키지 설치로 해결할수 있다.


보통은 아래와 같이 메뉴에서 게스트 확장 CD 이미지 삽입.. 이부분 누르면 된다고 하는데 나는 저 버튼을 눌러도 아무 반응이 없었다.




그래서 다른 방법을 찾아 보던중 패키지를 받아서 수동으로 설치해주는 방법을 찾게 되었다.


https://www.virtualbox.org/wiki/Downloads


위 사이트에 들어가면 아래와 같은 내용을 찾을 수 있다.



저 링크를 클릭해서 파일을 다운 받는다.




그리고 환경설정으로 들어가서 확장 메뉴에서 우측 버튼을 클릭해서 조금전 다운로드 받은 파일을 선택해준다. 




여기에서 설치를 진행하면 자동으로 알아서 다 실치가 된다.


그리고 나서 가상머신을 재부팅 해주고 나면 화면의 크기 조절시 해상도가 맞게 설정이 된다. 

728x90
반응형
반응형

컨트롤러를 만들어서 Testcase 를 작성한 후에 성공할거라 믿고 돌려봤는데 IllegalArgumentException 이 발생했다.

컨트롤러 코드와 테스트 케이스 코드는 각각 다음과 같다.


UserController.java

1
2
3
4
5
6
@GetMapping(value = "/users/{email}")
public UserDto.Res getUser(@PathVariable @Valid final String email){
    Optional<Users> users = userService.findByEmailValue(email);
 
    return new UserDto.Res(users.get());
}
cs


UserControllerTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@Before
public void setUp(){
    users = Users.builder()
            .email(Email.builder().value("test@test.com").build())
            .firstName("TEST")
            .lastName("KIM")
            .password("password")
            .build();
}
 
@Test
public void getUserTest() throws Exception {
 
    given(this.userController.getUser("test@test.com")).willReturn(new UserDto.Res(this.users));
 
    ResultActions resultActions = this.mockMvc.perform(
            get("/users/{email}""test@test.com"))
            .andDo(print());
 
    resultActions
            .andExpect(jsonPath("firstName").value("TEST"))
            .andExpect(jsonPath("lastName").value("KIM"))
            .andExpect(MockMvcResultMatchers.status().isOk());
}
cs


Exception

Caused by: java.lang.IllegalArgumentException: Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.


대체 뭐지??? 맞게 parameter 도 넘겼는데 왜 못찾는거지....



Spring Document 를 보니 다음과 같은 내용을 찾을수 있었다.

The matching of method parameter names to URI Template variable names can only be done if your code is compiled with debugging enabled. If you do have not debugging enabled, you must specify the name of the URI Template variable name to bind to in the @PathVariable annotation.

<출처 : https://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch18s02.html >


컴파일 할때 debugging enabled 가 되어야 동작을 하는데 그렇지 않을 경우에는 반드시 @PathVariable 사용시 name 에 값을 줘야 한다고 되어있다.


그럼 컴파일 할때 debugging enabled 는 뭔가?? -_-;;

java 소스를 컴파일할때 사용되는 javac 명령어를 찾아보면 다음과 같은 옵션이 있다. 컴파일시에 -g 옵션을 사용할 경우 로컬 지역변수(local variables) 를 포함한 debugging information 을 생성하고 디폴트로는 라인 넘버와 소스파일 정보만 생성된다고 써있다.


-g
Generate all debugging information, including local variables. By default, only line number and source file information is generated.
-g:none
Do not generate any debugging information.
-g:{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
source
Source file debugging information
lines
Line number debugging information
vars
Local variable debugging information

<출처 : https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html>



그럼 간단한 자바 클래스를 컴파일 해서 확인해보자.


1
2
3
4
5
6
public class Test {
    public static void main (String[] args) {
        String name = "test";
        System.out.println(name);
    }
}
cs

javac Test.java (옵션 없이 할경우)

1
2
3
4
5
6
7
8
9
10
11
12
13
# javap -l Test                                 
Compiled from "Test.java"                       
public class Test {                             
  public Test();                                
    LineNumberTable:                            
      line 4: 0                                 
                                                
  public static void main(java.lang.String[]);  
    LineNumberTable:                            
      line 6: 0                                 
      line 7: 3                                 
      line 8: 10                                
}                                               
cs


javac -g Test.java (-g 옵션을 붙여서 할경우)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# javap -l Test
Compiled from "Test.java"
public class Test {
  public Test();
    LineNumberTable:
      line 40
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0       5     0  this   LTest;
 
  public static void main(java.lang.String[]);
    LineNumberTable:
      line 60
      line 73
      line 810
    LocalVariableTable:
      Start  Length  Slot  Name   Signature
          0      11     0  args   [Ljava/lang/String;
          3       8     1  name   Ljava/lang/String;
}
cs


각각의 경우를 javap 명령어로 확인해 보았다. (javap 명령어는 컴파일된 class 파일을 역 어셈블 해주는 명령어 있다. -l 옵션을 붙이면 로컬변수 테이블까지 보여준다.)


첫번째에서는 기본적으로 라인만 보이는데 두번째에서는 로컬 변수까지 다 보여준다. 


결론적으로 맨 처음 Testcase 에서 발생했던 문제는 UserController.java 를 컴파일 했을때 -g 옵션이 안들어가서 컴파일 후에 @PathVariable 에 있는 변수를 못찾아서 발생한 문제였다. 이게 IntelliJ 에서 따로 compile 옵션설정을 해야 할지는 잘 모르겠는데 나는 @PathVariable 에 name 을 명시해주는 방법으로 해결을 했다.


참고자료

https://www.logicbig.com/tutorials/spring-framework/spring-web-mvc/spring-path-variable.html

https://objectpartners.com/2010/08/12/spring-pathvariable-head-slapper/

https://www.logicbig.com/tutorials/spring-framework/spring-web-mvc/parameter-name-discoverer.html

https://stackoverflow.com/questions/5746894/what-does-the-javac-debugging-information-option-gvars-do

728x90
반응형
반응형

- 숨겨진 폴더, 파일 보이기(Finder에서)


Shift + Command + .


- 화면 캡쳐


Command + control + 3 : 전체화면 캡쳐

Command + control + 4 : 영역 지정해서 캡쳐


728x90
반응형
반응형

gitignore 파일을 작성을 했는데 이상하게도 계속 해당 파일들이 Untracked Files 에 잡혔다.



그런데 분명히 내가 작성한 gitignore 파일에는 다음과 같이 존재하고 있었다.

.idea/

.DS_Store

그래서 구글링을 해보니 아래와 같이 해결책을 제시해줬다.


https://stackoverflow.com/questions/32384473/gitignore-not-ignoring-idea-path


첫번째 시도


git rm -rf .idea/


Git에서 파일을 제거하려면 git rm 명령으로 Tracked 상태의 파일을 삭제한 후에(정확하게는 Staging Area에서 삭제하는 것) 커밋해야 한다. 이 명령은 워킹 디렉토리에 있는 파일도 삭제하기 때문에 실제로 파일도 지워진다.

<출처 : https://git-scm.com/book/ko/v2/Git%EC%9D%98-%EA%B8%B0%EC%B4%88-%EC%88%98%EC%A0%95%ED%95%98%EA%B3%A0-%EC%A0%80%EC%9E%A5%EC%86%8C%EC%97%90-%EC%A0%80%EC%9E%A5%ED%95%98%EA%B8%B0>


그랬더니 다음과 같은 메세지가 나왔다.


fatal: pathspec '.idea/' did not match any files


상황을 보아 하니 rm 명령어가 Tracked 상태의 파일을 삭제하는 명령어 인데 위 파일들은 tracked 되지 않은 파일이기 때문에 없다고 나온것 같다.


두번째 시도


git clean -f -d .idea/


일단 이렇게 하니깐 Untracked 파일들이 다 지워지긴 했다.


그럼 이 명령어가 무엇을 의미하는지 한번 살펴보자.


워킹 디렉토리 청소하기

작업하고 있던 파일을 Stash 하지 않고 단순히 그 파일들을 치워버리고 싶을 때가 있다. git clean 명령이 그 일을 한다.

<출처 : https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-Stashing%EA%B3%BC-Cleaning >


결과적으로 Untracked 파일들을 모두 지운다는 의미이다.... -_-;; 좀 무서운 명령어다.  설명에도 다음과 같이 써있다.


이 명령을 사용할 때는 신중해야 한다. 이 명령을 사용하면 워킹 디렉토리 안의 추적하고 있지 않은 모든 파일이 지워지기 때문이다. 명령을 실행하고 나서 후회해도 소용없다. 지워진 파일은 돌아오지 않는다. git stash –all 명령을 이용하면 지우는 건 똑같지만, 먼저 모든 파일을 Stash 하므로 좀 더 안전하다.

워킹 디렉토리의 불필요한 파일들을 전부 지우려면 git clean 을 사용한다. 추적 중이지 않은 모든 정보를 워킹 디렉토리에서 지우고 싶다면 git clean -f -d 명령을 사용하자. 이 명령은 하위 디렉토리까지 모두 지워버린다. -f 옵션은 강제(force)의 의미이며 "진짜로 그냥 해라"라는 뜻이다.


한마디로 한번 지우면 되돌릴수 없다라는 의미이다. 

문제를 해결 하긴 했지만 위 명령어를 사용할 때에는 좀 신중할 필요는 있어보인다.



728x90
반응형

+ Recent posts