Fundamentals 7 min read

How to Retrieve Git User, Branch, Unpushed Commits, and Changed Files

This article explains how to use Git commands to obtain the current commit author, active branch, list of unpushed commits, and the files changed in each commit, and concludes with a promotional notice for a PHP online training class.

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Retrieve Git User, Branch, Unpushed Commits, and Changed Files

Earlier I completed a core code protection feature that notifies others when critical code is modified, and the following screenshots illustrate the effect.

In the implementation, several less‑common Git tricks are used, which are summarized below.

How to get the current commit user information

Run git config user.name to display the configured user name.

<code>zhangshixin</code>

Git config stores many settings such as aliases, user info, remote URLs, and branch data.

<code>alias.st=status
alias.co=checkout
alias.cb=checkout
alias.p=pull
alias.pr=pull
alias.pu=push
alias.cm=commit
alias.br=branch
alias.undo=reset
alias.rbc=rebase
alias.save=stash
alias.pop=stash
user.name=zhangshixin
[email protected]
[email protected]:android/xxx.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.Canary.remote=origin
branch.Canary.merge=refs/heads/Canary
pull.rebase=true</code>

How to get the current branch

Use git symbolic-ref --short HEAD which reads the .git/HEAD symbolic reference and returns the branch name (e.g., develop ).

How to list all local commits that have not been pushed

Execute git log @{u}.. --oneline to show the commits that exist locally but not in the upstream branch.

<code>4e4655b (HEAD -> master) 拦截跳转
f947180 修改文件</code>

Additional git log options allow you to compare local and remote commits, filter by date, and show file‑level changes.

<code>git log --pretty="%an(%cd) %h - %s" --since="2022-09-01" --no-merges --name-status</code>

The --pretty format customises output, --since limits the time range, --no-merges excludes merge commits, and --name-status displays file change status (M, D, A, R).

How to see which files a specific commit modified

After obtaining a commit ID, run git show --pretty="" --name-only $commitId to list only the affected files.

<code>app/src/main/java/com/example/shixindemo/MainActivity.kt</code>

In summary, by combining these Git commands you can build a core code protection mechanism that reports the current user, branch, unpushed commits, and the files changed in each commit.

Class Announcement

The article ends with a notice for the PHP Chinese website’s 22nd online live class, including enrollment details, teaching format, limited‑time offers, and contact information (QQ 27220243, WeChat phpcn01).

gitcommand-lineVersion ControlbranchcommitUnpushed Commits
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.