Do a "git export" (like "svn export")?
2023-02-27
Question I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the .git repository directory. There are at least three methods I know of: git clone followed by removing the .git repository directory. git checkout-index alludes to this functionality but starts with "Just read the desired tree into the index..." which I'm not entirely sure how to do. git-export is a third-party script that essentially does a git clone into a temporary location followed by rsync --exclude='.…
How to count total lines changed by a specific author in a Git repository?
2023-02-27
Question Is there a command I can invoke which will count the lines changed by a specific author in a Git repository? I know that there must be ways to count the number of commits as Github does this for their Impact graph. Answer This gives some statistics about the author, modify as required. Using Gawk: git log --author="_Your_Name_Here_" --pretty=tformat: --numstat \ | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "…
How do I do a 'git status' so it doesn't display untracked files without using .gitignore?
2023-02-26
Question How do I do a git status so it doesn't display untracked files without using .gitignore? I want to get modification status information on tracked files only. Answer Use this: git status -uno which is equivalent to: git status --untracked-files=no It's a bit hidden in the manuals, but the manpage for status says "supports the same options as git-commit", so that's where you'd have to look.
Add line break to 'git commit -m' from the command line"
2023-02-25
Question I am using Git from the command line and am trying to add a line break to the commit message (using git commit -m "") without going into Vim. Is this possible? Answer Certainly, how it's done depends on your shell. In Bash, you can use single quotes around the message and can just leave the quote open, which will make Bash prompt for another line, until you close the quote.…
How to list only the names of files that changed between two commits
2023-02-25
Question I have a bunch of commits in the repository. I want to see a list of files changed between two commits - from SHA1 to SHA2. What command should I use? Answer git diff --name-only SHA1 SHA2 where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:…
What does 'git blame' do?
2023-02-25
Question I saw a lot of questions about methods of using git blame, but I don't really understand them. I see a Blame button on top of files on the GitHub interface. Upon clicking it, it shows some diff with usernames on the left bar. What does that indicate? Why is git blame actually used, apart from GitHub? Answer From git-blame: Annotates each line in the given file with information from the revision which last modified the line.…
Git alias with positional parameters
2023-02-24
Question Basically I'm trying to alias: git files 9fa3 ...to execute the command: git diff --name-status 9fa3^ 9fa3 but git doesn't appear to pass positional parameters to the alias command. I have tried: [alias] files = "!git diff --name-status $1^ $1" files = "!git diff --name-status {1}^ {1}" ...and a few others but those didn't work. The degenerate case would be: $ git echo_reverse_these_params a b c d e e d c b a .…