Git Ignore and Cleanup Flashcards

1
Q

Q: What is .gitignore in Git?

A

A: A file that specifies files or patterns that Git should ignore and not track.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: How do you ignore all .log files in a repository?

A

A: Add *.log to the .gitignore file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How do you ignore a specific file, e.g., config.php?

A

A: Add config.php to the .gitignore file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How do you ignore an entire directory, e.g., node_modules/?

A

A: Add node_modules/ to the .gitignore file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: How do you create a .gitignore file?

A

A: Create a file named .gitignore in the root of the repository and add patterns to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How do you exclude .gitignore from being ignored itself?

A

A: Ensure .gitignore is not listed in .gitignore.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: How do you list all ignored files in a repository?

A

A: Use git status –ignored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What happens if a file already tracked by Git is added to .gitignore?

A

A: Git will continue tracking it until it is manually removed from the index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: How do you stop tracking a file without deleting it from the working directory?

A

A: Use git rm –cached <file>.</file>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: How do you ignore all files in a directory except one, e.g., keep important.txt in docs/?

A

A: Add docs/* and !docs/important.txt to .gitignore.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: What is the difference between .gitignore and .git/info/exclude?

A

A: .gitignore is shared and tracked by Git, while .git/info/exclude is local and not shared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: How do you globally ignore files across all repositories?

A

A: Add patterns to a global ignore file and configure it using git config –global core.excludesfile <path>.</path>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: How do you untrack all files listed in .gitignore?

A

A: Use git rm -r –cached ., then git add ., and commit the changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What does git clean do?

A

A: Removes untracked files and directories from the working directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: How do you perform a dry-run of git clean to see what would be removed?

A

A: Use git clean -n.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: How do you remove untracked files in Git?

A

A: Use git clean -f.

17
Q

Q: How do you remove untracked directories in Git?

A

A: Use git clean -fd.

18
Q

Q: How do you remove untracked files and directories, including ignored files?

A

A: Use git clean -fxd.

19
Q

Q: What is the purpose of git gc?

A

A: git gc runs garbage collection, optimising the repository by cleaning up unnecessary files and objects.

20
Q

Q: How do you clean up dangling objects in Git?

A

A: Use git gc –prune=<time> or git prune.</time>

21
Q

Q: What does git prune do?

A

A: Removes unreachable objects from the repository.

22
Q

Q: How do you identify large files in your repository?

A

A: Use git rev-list –objects –all | sort -k 2.

23
Q

Q: How do you remove a large file from the entire Git history?

A

A: Use git filter-repo or BFG Repo-Cleaner.

24
Q

Q: How do you avoid committing large or sensitive files in the first place?

A

A: Add them to .gitignore or use Git LFS for large files.

25
Q

Q: How do you prevent git clean from removing ignored files?

A

A: Do not use the -x flag when running git clean.