Git Logs and History Flashcards
Q: How do you view the commit history of a repository?
A: Use git log.
Q: How do you view a simplified commit history in one line per commit?
A: Use git log –oneline.
Q: How do you limit the number of commits displayed in git log?
A: Use git log -n <number>, e.g., git log -n 5 for the last 5 commits.</number>
Q: How do you view the log for a specific file?
A: Use git log <file>.</file>
Q: How do you view the changes introduced by a specific commit?
A: Use git show <commit-hash>.</commit-hash>
Q: How do you view the differences between two commits?
A: Use git diff <commit1> <commit2>.</commit2></commit1>
Q: How do you search for a commit by message in the log?
A: Use git log –grep=”<keyword>".</keyword>
Q: How do you display logs with commit messages containing a specific author?
A: Use git log –author=”<author>".</author>
Q: How do you view logs from a specific date range?
A: Use git log –since=”YYYY-MM-DD” –until=”YYYY-MM-DD”.
Q: How do you include the changes (diffs) in the log output?
A: Use git log -p.
Q: How do you show a specific number of lines of diff context in the log?
A: Use git log -U<n>, e.g., git log -U3 for 3 lines of context.</n>
Q: How do you show a graphical representation of branches in the log?
A: Use git log –graph.
Q: How do you combine oneline, graph, and branch decorations in the log?
A: Use git log –oneline –graph –decorate.
Q: How do you show the commit history for a specific branch?
A: Use git log <branch-name>.</branch-name>
Q: How do you find commits that affected a specific line in a file?
A: Use git blame <file>.</file>