포스트

2021-03-18-TIL

2021-03-18-TIL

공부 링크


원하지 않는 커밋, 파일을 완전히 제거하는 방법

파일을 지우는 커밋을 새로 만들어도 그 파일은 이전 커밋들의 스냅샷에 그대로 남아 있다. 저장소 이력에서 파일을 완전히 없애려면 그 파일이 들어 있는 모든 커밋을 다시 써야 한다. 최근 커밋 몇 개라면 git rebase -i로 고칠 수 있지만, 이력 전체에서 특정 파일을 지우려면 BFG Repo-Cleaner 같은 전용 도구가 편하다.

BFG 문서가 안내하는 순서는 다음과 같다.

  1. git clone --mirror로 저장소를 bare 형태로 복제한다.
  2. java -jar bfg.jar --delete-files <파일> <저장소>.git처럼 BFG를 실행해 이력을 다시 쓴다.
  3. git reflog expire --expire=now --all && git gc --prune=now --aggressive로 더 이상 참조되지 않는 객체를 실제로 지운다.
  4. 원격 저장소에 푸시한다.

아래는 BFG를 실행하고 푸시한 결과다.

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 ~/Desktop/untitled folder/test  java -jar bfg-1.14.0.jar --delete-files 2021-03-15-TIL.md polynomeer.github.io.git

Using repo : /Users/ham/Desktop/untitled folder/test/polynomeer.github.io.git

Found 323 objects to protect
Found 2 commit-pointing refs : HEAD, refs/heads/main

Protected commits
-----------------

These are your protected commits, and so their contents will NOT be altered:

 * commit 5803b18a (protected by 'HEAD') - contains 1 dirty file :
	- TIL/2021-TIL/2021-03-TIL/2021-03-15-TIL.md (2.5 KB)

WARNING: The dirty content above may be removed from other commits, but as
the *protected* commits still use it, it will STILL exist in your repository.

Details of protected dirty content have been recorded here :

/Users/ham/Desktop/untitled folder/test/polynomeer.github.io.git.bfg-report/2021-03-18/17-21-28/protected-dirt/

If you *really* want this content gone, make a manual commit that removes it,
and then run the BFG on a fresh copy of your repo.

Cleaning
--------

Found 96 commits
Cleaning commits:       100% (96/96)
Cleaning commits completed in 83 ms.

Updating 1 Ref
--------------

	Ref               Before     After
	-------------------------------------
	refs/heads/main | 5803b18a | 00750bd2

Updating references:    100% (1/1)
...Ref update completed in 20 ms.

Commit Tree-Dirt History
------------------------

	Earliest                                              Latest
	|                                                          |
	...........................................................D

	D = dirty commits (file tree fixed)
	m = modified commits (commit message or parents changed)
	. = clean commits (no changes to file tree)

	                        Before     After
	-------------------------------------------
	First modified commit | 4b6755df | 7b6836e4
	Last dirty commit     | 4b6755df | 7b6836e4

Deleted files
-------------

	Filename            Git id
	-------------------------------------
	2021-03-15-TIL.md | dd40ee9a (2.5 KB)

In total, 6 object ids were changed. Full details are logged here:

	/Users/ham/Desktop/untitled folder/test/polynomeer.github.io.git.bfg-report/2021-03-18/17-21-28

BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive
 ~/Desktop/untitled folder/test  git push --force                                                               ✔  3476  17:21:38
fatal: not a git repository (or any of the parent directories): .git
 ~/Desktop/untitled folder/test  cd ./polynomeer.github.io.git                                              128 ↵  3477  17:21:59
 ~/Desktop/untitled folder/test/polynomeer.github.io.git   main  git push --force                             ✔  3478  17:22:05
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 16 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 5.04 KiB | 5.04 MiB/s, done.
Total 10 (delta 3), reused 5 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://github.com/Polynomeer/polynomeer.github.io.git
 + 5803b18...00750bd main -> main (forced update)
 ~/Desktop/untitled folder/test/polynomeer.github.io.git   main 

출력에서 두 가지를 볼 수 있다.

첫째, Protected commits 경고다. BFG는 기본적으로 현재 브랜치의 최신 커밋(HEAD)은 건드리지 않는다. 문서에 따르면 최신 커밋은 실제로 배포되는 코드일 가능성이 높아서, 그 안의 파일을 지우면 동작이 깨질 수 있기 때문이다. 그래서 HEAD 커밋 5803b18a에 지우려는 파일이 들어 있으면, 그 이전 커밋들에서는 지워도 HEAD에는 남는다는 경고가 나온다. 완전히 지우려면 출력의 안내대로 파일을 지우는 커밋을 먼저 만든 뒤, 새로 복제한 저장소에 BFG를 다시 실행해야 한다.

둘째, 첫 git push --force가 fatal: not a git repository로 실패했다. bare 저장소는 polynomeer.github.io.git 디렉터리 자체가 Git 저장소이고 상위 디렉터리는 저장소가 아니므로, 그 디렉터리 안으로 들어가서 푸시해야 한다. 디렉터리를 옮긴 뒤의 푸시는 main -> main (forced update)로 성공했다.

GitHub 문서는 이 작업에 대해 몇 가지를 경고한다. 이력을 다시 쓰면 그 파일을 처음 넣은 커밋과 그 뒤의 모든 커밋 해시가 바뀐다. 또 이미 다른 사람이 복제했거나 포크한 저장소에는 데이터가 남아 있을 수 있다. 지우려는 것이 비밀번호나 키 같은 비밀 정보라면, 이력을 고치기 전에 그 값을 먼저 폐기하거나 교체하라고 권한다.


textarea 기본값

<input>은 value 속성으로 기본값을 주지만, <textarea>는 여는 태그와 닫는 태그 사이의 내용이 기본값이다. HTML 표준은 textarea의 초기화(reset) 동작을 원래 값(raw value)을 요소의 자식 텍스트 내용으로 되돌리는 것으로 정의한다.

1
<textarea name="contents">기본으로 들어갈 내용</textarea>

태그 사이의 공백도 값에 들어간다. HTML 파서는 여는 태그 바로 뒤에 오는 줄바꿈 하나만 편의상 무시하므로, 그 뒤에 들여쓰기 공백을 넣으면 공백까지 기본값이 된다.

참고한 자료외부 출처 4

외부 출처

이 글은 저작권자의 CC BY 4.0 라이선스를 따릅니다.

댓글

아직 댓글이 없습니다