Git: 특정 commit 으로 이동 후, amend 하기


Git 으로 local branch 를 생성 한 후, 특정 source 를 수정함에 있어 여러개의 commit 이 만들어 질 수 있다.

이 때, 기존에 했던 commit 에 추가적인 수정을 하려면 git add/commit --amend 를 하면 되는데 최상위에 있는

commit 은 바로 수정 후, git add/git commit --amend 하면 적용이 되지만 현재 수정하려는 내용이 이전에 있던 commit 에 반영되었으면 하는 경우가 발생한다.


예를 들어, 아래와 같이 commit 들이 있다고 가정하자.

commit ec88cc08f5a29f98a3c5f14ca642f235fb1c0fb8

Author: Daeseok Youn <daeseok.youn@gmail.com>

Date:   Fri Feb 28 15:34:22 2014 +0900


    staging: cxt1e1: fix checkpatch errors with open brace '{'


    clean up checkpatch.pl error:

     ERROR: that open brace { should be on the previous line


    Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>


commit 6007a41fffd430b79775871a2c9eb6c35eb3e6a6

Author: Daeseok Youn <daeseok.youn@gmail.com>

Date:   Fri Feb 28 15:27:51 2014 +0900


    staging: cxt1e1: fix checkpatch error 'assignment in if condition'


    checkpatch.pl error:

     ERROR: do not use assignment in if condition


    Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>


commit aa877600a98048d056b65d0c9e7426616e9ccc2f

Author: Daeseok Youn <daeseok.youn@gmail.com>

Date:   Fri Feb 28 15:22:13 2014 +0900


    Staging: cxt1e1: Fix line length over 80 characters in hwprobe.c


    clean up checkpatch.pl warnings:

     WARNING: Line length over 80 characters


    Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>


commit 2f61d921981a45c687e5dc26d6f7e6a3925ca0e5

Author: Daeseok Youn <daeseok.youn@gmail.com>

Date:   Fri Feb 28 15:14:39 2014 +0900


    staging: cxt1e1: Fix no spaces at the start of a line in hwprobe.c


    clean up checkpatch.pl warnings:

    WARNING: please no spaces at the start of a line in


    Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>


이 때, 추가적인 수정사항이 발생 되었는데, 이 내용이 맨 아래에 있는 "staging: cxt1e1: Fix no spaces at the start of a line in hwprobe.c" 에 적용되었으면 하는 바램이 생겼다.


그렇다면, 일단 그 commit 을 수정할 수 있는 mode(?) 로 가야한다.

$ git rebase --interactive 2f61d921981a45c687e5dc26d6f7e6a3925ca0e5^

라고 한다. 맨 마지막에 "^" 를 넣어줘야 그 commit 을 포함하여 rebase  를 진행한다.


위에서 처럼 입력하면, 나의 경우는 vim 이 열리면서 아래와 같은 내용이 입력된다.

pick 2f61d92 staging: cxt1e1: Fix no spaces at the start of a line in hwprobe.c

pick aa87760 Staging: cxt1e1: Fix line length over 80 characters in hwprobe.c

pick 6007a41 staging: cxt1e1: fix checkpatch error 'assignment in if condition'

pick ec88cc0 staging: cxt1e1: fix checkpatch errors with open brace '{'


# Rebase b9ea35b..ec88cc0 onto b9ea35b

#

# Commands:

#  p, pick = use commit

#  r, reword = use commit, but edit the commit message

#  e, edit = use commit, but stop for amending

#  s, squash = use commit, but meld into previous commit

#  f, fixup = like "squash", but discard this commit's log message

#  x, exec = run command (the rest of the line) using shell

#

# If you remove a line here THAT COMMIT WILL BE LOST.

# However, if you remove everything, the rebase will be aborted.

#


여기서 내가 수정하고 싶은 것은 맨 위에 있는 commit 이다. "pick" 을 "edit" 로 변경하고 저장 하고 나와 git log를 하면

최상위에 그 commit 이 올라와 있다. 


이제 원하던 수정을 하자.


수정이 완료되면,

$ git add <file>

$ git commit --amend


이렇게 하면 일단 현재 원하던 commit 에 추가 반영이 된다.


이제 원래 갖고 있던 commit 들을 복구 해야 한다.

$ git rebase --continue


이렇게 하면 수정한 commit 이 후에 생성된 commit 들을 merge 하기 시작한다. 하나씩 merge 를 하다가 conflict 날 수 있다.

그러면 rebase 가 중지 되고, conflict 를 해결 한 후에 다시 git rebase --continue 를 입력하라고 한다.


이렇게 해서 마지막으로

Successfully rebased and updated ref/heads/<local branch name>

이라고 나오면 성공한 것이다.



'Development Tip' 카테고리의 다른 글

VIM 에서 spelling 확인하기  (0) 2016.07.08
Git add -p 로 수정사항 분리하기  (0) 2014.04.16
const char* vs. char const*  (0) 2014.02.19
Fish shell environment  (0) 2013.12.03
Kernel mailing list 활용 방법  (0) 2013.11.08

const char* vs. char const*


code 를 보다 보니 C/C++ 에서 사용하는 const 에 대한 내용은 알고 있지만, 막상 보면 어디가 상수로 결정되어 수정될 수 없는지 계속 찾아 보게된다. 


그래서 검색을 해보았더니, 예제로 잘 정리된 내용이 있어 갖고 왔다.

original url : http://stackoverflow.com/questions/162480/const-int-vs-int-const-as-function-parameter-in-c-and-c


아래서 처럼 const int 와 int const 는 같은 의미로 사용되어 진다.

const int a = 1; // read as "a is an integer which is constant"
int const a = 1; // read as "a is a constant integer"

그래서 아래와 같이 2를 넣을 수 없다.

a = 2; // Can't do because a is constant

하지만 pointer 변수일 때는 다르게 해석이 되는데, 하나는 주소값을 변경하지 못하는 것과 다른 하나는 주소가 가리키고 있는 값의 변경을 할 수 없는 것이다. 아래의 주석을 잘 읽어보면 이해가 될 것이다.

const char *s;      // read as "s is a pointer to a char that is constant"
char c;
char *const t = &c; // read as "t is a constant pointer to a char"

*s = 'A'; // Can't do because the char is constant
s++;      // Can do because the pointer isn't constant
*t = 'A'; // Can do because the char isn't constant
t++;      // Can't do because the pointer is constant


Install Fish Shell on Ubuntu


Fish shell 이라는 것이 생겼다. 이 shell 의 가장 큰 특징은 자동 완성기능인데, 특정 command 의 man page를 parsing 해서 option 까지 자동완성해준다. 기본적으로 현재 typing 하고 있는 command 의 hint 기능도 있다. 


또 하나 큰 특징은 shell 에서 script 작성 및 실행이 가능하다는 것이다.(command line 에서 편집기 editor 처럼 동작이 가능하다는 것이다!) 


이러한 모든 기능의 설명은 http://fishshell.com/docs/current/index.html 에서 확인할 수 있다.


여기서는 ubuntu 에 fish shell 의 설치 방법과 간단한 기능들을 살펴 본다.

(Bash shell 에서 지원하는 것은 일단 다 지원하는 듯 하다)


1. Installation.

sudo apt-add-repository ppa:fish-shell/release-2

$ sudo apt-get update

$ sudo apt-get install fish


2. 실행

$ fish


3. 기본 shell 로 등록

$ chsh -s /usr/bin/fish


2 번 실행으로 사용하다가 괜찮다 싶으면 기본 shell 로 등록해서 사용하면 될 것이다.


4. Commands hint



위에 그림 처럼 최근 history base 로 vi 를 입력했을 때 회색으로 되어 있는 부분이 자동 완성 될 문장이다. 간단히 화살표 오른쪽을 누르면 그  command 를 바로 이용할 수 있다.(화살표 위/아래를 하면 vi 와 관련된 history command 들간 이동이 가능하다.)


5. Edit script



쉘에서 바로 script 를 작성할 수 있다. 위의 그림처럼 간단히 작성 가능하고 위/아래로 움직여서 수정도 가능하다. 정말 editor 처럼 동작한다.

실제 예로는 현재 시점에서 prompt 모양을 변경할 경우 이렇게도 사용할 수 있을 것이다.

(나머지는 http://fishshell.com/docs/current/index.html 으로 이동해서 확인 바란다.)


'Development Tip' 카테고리의 다른 글

Git: 특정 commit 으로 이동 후, amend 하기  (0) 2014.02.28
const char* vs. char const*  (0) 2014.02.19
Kernel mailing list 활용 방법  (0) 2013.11.08
PuTTY 설정 값 공유하는 방법  (0) 2013.10.07
Git with eclipse  (0) 2013.04.04

+ Recent posts