Five Advanced Git Commands to Boost Your Development Efficiency

This article introduces five powerful Git commands—stash, reset --soft, cherry-pick, revert, and reflog—explaining their basic usage and advanced tricks, enabling developers to manage temporary changes, roll back commits, copy changes across branches, undo mistakes, and recover lost history efficiently.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Five Advanced Git Commands to Boost Your Development Efficiency

Author Peng Lei shares five advanced Git commands that go beyond the usual pull and push, helping developers work faster and appear more proficient.

1. stash: Store temporary changes

Use

# 存储当前的工作现场
git stash save "修 bug 之前的中断点"

to save both staged and unstaged changes, then switch branches. View saved entries with

# 查看 stash 列表
git stash list

. Restore with

# 恢复之前存储的工作现场
git stash pop

or keep the stash using git stash apply. Advanced:

# 只存储工作区的改动,不包含暂存区
git stash save --keep-index "仅存储工作区的改动"

and

# 存储未跟踪文件
git stash save -u "包含未跟踪文件的改动"

.

2. reset --soft: Soft rollback

Move HEAD back while keeping working‑directory changes:

# 回到上一个 commit,但保留工作目录的改动
git reset --soft HEAD^

. Roll back to any commit with

# 回到指定 commit
git reset --soft <commit-hash>

.

3. cherry-pick: Copy a commit

Apply a specific commit to the current branch:

# 把特定 commit 应用到当前分支
git cherry-pick <commit-hash>

. Resolve conflicts with git cherry-pick --continue or skip a problematic commit with git cherry-pick --skip.

4. revert: Undo a commit

Create a new commit that reverses a previous one:

# 撤销特定的 commit
git revert <commit-hash>

. Revert a range with

# 撤销一系列的 commit
git revert <oldest-commit-hash>..<newest-commit-hash>

or generate the revert without committing using git revert --no-commit <commit-hash>.

5. reflog: View reference log

List all Git actions, including those that seem lost:

# 查看所有的操作记录
git reflog

. Recover a previous state with

# 恢复到某个历史节点
git reset --hard <reflog-index>

. Advanced: view a branch’s reflog with

# 查看某个分支的 reflog
git reflog show <branch-name>

and clean old entries with

# 清理 reflog 记录
git reflog expire --expire=now --all

.

The article concludes by encouraging readers to adopt these commands to improve productivity and showcase Git mastery.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GitProductivitysoftware-developmentbackend-developmentcommand-lineversion-control
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

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.