On this page
- Used shell commands in the module's code
- which find
- git --version
- git ls-remote --tags --sort="v:refname" git://github.com/git/git.git | tail | sed 's/.*\/v//; s/\^{}//; s/^[0-9].\+-rc[0-9]//; /^$/d;' | tail -n1
- whoami
- who -q
- [ -d /path/to/folder ] && echo "1"
- find $PWD -name "*.git" -type d | grep -e ".git$" | sort
- locate "$PWD*/.git" | grep -e ".git$" | sort
- which git
- git rev-parse --abbrev-ref HEAD
- git checkout @{-1}
- git reflog -1
- git config --get remote.origin.url
- fetch -q; git log HEAD..@{u} --format="%at⁏%an⁏%ae⁏%cn⁏%ce⁏%h⁏%s"
- [ $(git rev-parse HEAD) = $(git ls-remote $(git rev-parse --abbrev-ref @{u} | \sed 's/\// /g') | cut -f1) ] && echo Up to date || echo Not up to date (removed)
- git config user.email "temporary@email.com
- git merge FETCH_HEAD 2>&1
- git config --unset user.email
- git status
- git status -s | while read mode file; do echo $mode $(stat -c %Y $file) $file; done
- git tag --points-at HEAD
- stat -c %Y .git/FETCH_HEAD (removed)
- git log -1 --format="%at⁏%an⁏%ae⁏%cn⁏%ce⁏%h⁏%s"
- git clean -ndX
- ls | wc -l
- git submodule status | cut -d\' \' -f3-4
- git stash list --format='%gd (%cr): %gs'
Concept
The GIT Info Report module executes several Git commands on the current or another environment and shows the output on the Status report at ../admin/reports/gitinfo. It uses shell_exec() for it (see command - PHP exec() vs system() vs passthru() - Stack Overflow).
This page lists the commands used by the code programmatically to generate the report. You could use them also from the terminal when in a Git repo. The module shows the info for all Git folders it detects recursively, from the project root down to the deepest folder. It does so even for projects outside of the current Drupal install if you define them in the settings., also non-Drupal or non-PHP projects. As long as they contain Git repositories.
Used shell commands in the module's code
In order of appearance in the code.
which find
Checks where the terminal command 'find' is located. We use the output to check if the command is available. If not, that indicates that the server's OS is probably non-Unix.
git --version
Shows the current Git version (and checks if Git is available).
git ls-remote --tags --sort="v:refname" git://github.com/git/git.git | tail | sed 's/.*\/v//; s/\^{}//; s/^[0-9].\+-rc[0-9]//; /^$/d;' | tail -n1
Gets the latest stable Git version available to check if the current used version is up to date.
whoami
Gets the current shell username. Executed from within the code that is most likely to be www-data.
who -q
Names of the users logged in. Executed from within the code on a local machine that would return the shell username of the normal user that executes Git commands locally. We can now show that together with the previous (www-data) in case we encounter a permission issue connecting to the remote repo, together with a link to instructions on how to solve.
[ -d /path/to/folder ] && echo "1"
Returns 1 (TRUE) is the directory exists. Used to check.
find $PWD -name "*.git" -type d | grep -e ".git$" | sort
To create a list of all detected Git folders to loop through with the below commands.
Recursively check for git directory updates - Stack Overflow.
Introduced in #3076204: Use 'find' as fallback for 'locate'.
locate "$PWD*/.git" | grep -e ".git$" | sort
Before, we used 'locate' instead of 'find' because it returns the full paths of the Git folders and is quicker. But if a GIT folder does not show immediately, you need to clear the locate cache, see How to update Linux "locate" cache - Unix & Linux Stack Exchange. We found that a bit awkward, so we replaced it with the 'find' command, as mentioned above.
Some more background in #3081356: Use 'find' instead of 'locate'.
which git
Returns the location path where git is installed.
git rev-parse --abbrev-ref HEAD
Gives the current branch.
git checkout @{-1}
Does a checkout of the previous branch. We use that to fix a 'HEAD detached' state (not on a branch).
git reflog -1
Show the last line of the reference log. We store that in the DB log to capture the associated hash of the branch change as a result of a 'HEAD detached' fix.
git config --get remote.origin.url
How can I determine the URL that a local Git repository was originally cloned from? - Stack Overflow.
If the remote starts with git@.. instead of https://.. it indicates it has been cloned through SSH.
Introduced in #2927747: Show the remote URL.
fetch -q; git log HEAD..@{u} --format="%at⁏%an⁏%ae⁏%cn⁏%ce⁏%h⁏%s"
Get all the commits messages on the remote that are not on the local branch (behind) together with the author, committer, and on the report a fuzzy timestamp (time ago) showing the exact date and time on mouse hover.
[ $(git rev-parse HEAD) = $(git ls-remote $(git rev-parse --abbrev-ref @{u} | \sed 's/\// /g') | cut -f1) ] && echo Up to date || echo Not up to date (removed)
Check if pull needed in Git - Stack Overflow.
Compares the current branch's HEAD commit hash against its remote upstream branch without affecting the repo itself.
Introduced in #3088913: Check if pull is needed. This was removed as a git fetch (see above) is much more performant while giving also more information.
git config user.email "temporary@email.com
When using git as the user www-data, it should identify itself with at least an email address, even if non-existing.
git merge FETCH_HEAD 2>&1
Merges the retrieved branch heads into the current branch and uses the produced output (2>&1).
bash - In the shell, what does " 2>&1 " mean? - Stack Overflow
git config --unset user.email
To remove the previously set temporary email for user www-data on the current repo git config. This is harmless as a local "real" user will have set a global git email address.
git status
Shows the current branch, detects untracked files and local file changes. Highlighted in red:
- Changed but not updated (for older Git versions)
- Changes not staged for commit
- Changes to be committed
- Your branch is ahead (you should push your changes)
- Your branch is behind (you should pull changes from the repo)
- No commits yet (a new repo, make an initial commit on it)
- HEAD detached (the commits you are making do not belong to a branch)
- Remote: Not added yet (see the remote command above, it makes no sense to have Git only locally)
- Untracked files
- files would be overwritten by merge
- A 'git pull' failed
git status -s | while read mode file; do echo $mode $(stat -c %Y $file) $file; done
To list an unstaged file's last modified date alongside its path.
git status - list last modified date - Stack Overflow
Introduced in #3085520: Show list of file changes with status and timestamp.
git tag --points-at HEAD
Shows all tags on the current HEAD (or commit). If no tag exists on a server environment probably branches are used for release management.
git checkout - Show which git tag you are on? - Stack Overflow.
stat -c %Y .git/FETCH_HEAD (removed)
Last pull timestamp. On the Status report as a fuzzy timestamp (time ago) showing the exact date and time on mouse hover.
How do I check the date and time of the latest `git pull` that was executed? - Stack Overflow.
Introduced in #2895583: Add latest pull date and time. Removed as it resulted to be unreliable.
git log -1 --format="%at⁏%an⁏%ae⁏%cn⁏%ce⁏%h⁏%s"
The last commit message together with the author, committer, and on the report a fuzzy timestamp (time ago) showing the exact date and time on mouse hover.
How to read last commit comment? - Stack Overflow.
git clean -ndX
List of ignored existing folders and files.
Git command to show which specific files are ignored by .gitignore - Stack Overflow.
Introduced in #2900450: List the folders in the .gitignore file.
ls | wc -l
Count the total number of items in the current directory, both files and folders (not recursive).
git submodule status | cut -d\' \' -f3-4
Shows the detected submodules of the current repo.
List submodules in a Git repository - Stack Overflow.
git stash list --format='%gd (%cr): %gs'
List the stash entries that you currently have. The format has been added to show a fuzzy timestamp as well a stash name given, if so.
Git - git-stash Documentation.
Introduced in #3073932: Wrong severity.
Note that git stashes only exist locally and will normally not get pushed. Having stashes will result in a warning just as a reminder, suggesting to 'pop', 'drop' or 'clear'.
Is git stash stack pushed to the remote repo? - Stack Overflow.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion