200727 TIL: Git과 JS 토막 지식

1 minute read

Git

Required Commands

  • add: 변경된 파일 staging에 추가

    git add file.js (해당파일)

    git add -A (전체파일)

  • commit: 변경사항 커밋하기

    git commit -m "수정 내용"

  • branch: 브랜치 목록보기

    git branch (목록보기)

    git branch new_branch (새 브랜치 만들기)

  • checkout: 다른 브랜치 생성

    git checkout branch_name (새로운 브랜치 생성하고 체크아웃)

  • merge: 브랜치 병합

    git merge commit

참고한분 블로그 링크

Process

내가 진행했던 PR 과정은 다음과 같다.

fork → clone → 코드 수정 → add → commit → push → pull requests

원본 repository에서 내 저장소로 fork해온후, 그것을 local에서 작업하기 위해 clone한다. 원하는 대로 코드를 수정하고 나서 변화된 것 중 commit 하고 싶은 것을 add 하여 스테이징 영역에 추가한다. 추가한 이후, commit과 push를 하여 내 저장소에 적용한다. 원본에 push 권한이 없을 경우 pull request를 하여 기여할 수 있다. pull request는 당장 merge하지 않고 코드 충돌을 막을 수 있게 된다.

Branch

독립적으로 어떤 작업을 진행하기 위한 개념으로, 여러 명이 동시에 작업을 진행할 때 영향을 주지 않도록 사용한다. 작업의 단위라 볼 수 있다.

Node

node file.js
: 터미널 환경에서 해당 파일 실행 가능

Commit Convention

Commit message를 아무렇게나 작성할 수 있지만 여러 사람들과 함께 일하려면 규칙은 필요할 것 같아 찾아보았다. Udacity에서 제공하는 가이드 중, commit 메세지 가장 위 type에 대한 부분이다.

Udacity guide style: https://udacity.github.io/git-styleguide/

feat: a new feature
fix: a bug fix
docs: changes to documentation
style: formatting, missing semi colons, etc; no code change
refactor: refactoring production code
test: adding tests, refactoring test; no production code change
chore: updating build tasks, package manager configs, etc; no production code change

JavaScript

// 매개변수가 있을 때
const materials = [
  'Hydrogen',
  'Helium',
  'Lithium',
  'Beryllium'
];
console.log(materials.map(material => material.length));
// 매개변수가 없을 때
const hungry = () => console.log("hungry now");
  • for of: 컬렉션 전용 반복 구문 (파이썬의 for .. in 과 비슷한 것 같다.)
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
  console.log(element);
}
  • repeat: 문자열 반복
'abc'.repeat(2); // 'abcabc'
  • readline(): 입력을 받을 때
// 한 줄만 입력 받을 때
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  console.log(line);
  reader.close();
});

회고

함수로 분리 할수록 코드를 훨씬 쉽게 관리할 수 있다. 더 작은 단위, 더 효과적인 단위로 나눌 수 있지 않을까 내 지난 코드를 곱씹게 된다.. ㅠㅠ 원하는 결과를 먼저 반환하는 메인 기능부터 만들어 코드를 짜는 것이 좋을 것 같다.

디버깅 기능에 대해 잘 몰라서 print()나 console.log로 연명 했는데 디버깅 기능도 활발히 사용해 좀 더 빠르게 개발할 수 있으면 좋겠다.