Hot answers tagged

7

$() is replaced with the output of the given command, not its exit code. To use an exit code, use the command directly with if: if git merge-base --is-ancestor "$COMMIT_ID" HEAD; then


4

First, the -execdir command looks wonky (2x $SHELL -c?): $SHELL -c '[ ! -d ".git" ] && echo "not git repo:" {}' $SHELL -c '{}' ';' Also, -execdir runs the command in the directory containing the matched entity, (so the parent directory of the directory that it is checking right now), which is . for all subdirectories. The test is run in the wrong ...


3

Yes, grep can do something like this: its -C option will show the context of a match. Thus git help | grep -C2 merge will show lines containing “merge”, with two lines of context above and below. I find it more convenient to use less: git help | less then search using /. git help won’t tell you much though, you’ll need git help merge which will open ...


2

Git does nothing but read from the file. This will definitely not break the pipe. You can even create a git repository for a read-only directory and commit read-only files. As long as you're only adding and committing stuff, rather than doing anything that checks something out or modifies the working directory, the only place where Git needs to write is ...


2

muru’s answer explains what’s wrong with your approach. The answers to the question you referred to suggest a simpler approach with no shell involved: find . -maxdepth 1 -type d -exec test '!' -e '{}/.git' ';' -printf "not git repo: %p\n" (assuming your find supports -printf), or find . -maxdepth 1 -type d -exec test '!' -e '{}/.git' ';' -print This ...


1

On it's own Git will not record metadata such as permissions which are required for a correct backup of /etc.


1

Have you seen etckeeper? etckeeper is a collection of tools to let /etc be stored in a git, mercurial, bazaar or darcs repository. This lets you use git to review or revert changes that were made to /etc. Or even push the repository elsewhere for backups or cherry-picking configuration changes. It hooks into package managers like apt to automatically ...


1

This will list all your remote URLs for remotes named “origin” in any git repositories beneath the current directory: find . -path '*/.git/config' -execdir git remote get-url origin \; It finds files named config inside a .git directory, and from every containing directory, runs git remote get-url origin which shows the remote URL for the “origin” remote ...


Only top voted, non community-wiki answers of a minimum length are eligible