工作中常用的git命令,千万不能忘

1、设置当前分支为默认分支:

git branch --set-upstream-to=origin/master

2、To push the current branch and set the remote as upstream, use:

git push --set-upstream origin eds_enhancement

3、同步远程分支

git remote update --prune [remote]

4、Remove a file from a Git repository without deleting it from the local filesystem

For single file:

git rm --cached mylogfile.log

For single directory:

git rm --cached -r mydirectory

5 undo git add . from staged

git reset

git reset <file path>

or undo all staged files:

git reset HEAD .

6 commit to gateWay

git push origin HEAD:refs/for/19.1.1_sparkle

7 撤销提交

git revert [commit id]

8 查看文件变动

git show --name-only {commit}

9 squash commits to one(将多个commits压成一个)

git rebase -i [commit-id (not contained it)]

note:

select by `s` short command

10 在最近的commit上追加文件变动

git add the_left_out_file

git commit --amend --no-edit

or

git reset HEAD^

git add again

11 撤回部分file的commit

step 1: git reset --soft HEAD^1

step 2: git reset <file path>

git rm --cached <file-name>(如果要刪除此文件)

12 恢复reset

git reflog

13 list all conflict files

git diff --name-only --diff-filter=U

14 add message to stash command

git stash save <messages>

15 rebase local branch with remote master

step1: git fetch origin # Updates origin/master

step2: git rebase origin/master # Rebases current branch onto origin/master

16 change commit message to latest commit

git commit --amend -m "New commit message."

17 git log --author=<author name>

18 git alias

git config --global alias.p 'push'

git p

相关推荐
拾-光几秒前
【Git】命令大全:从入门到高手,100 个最常用命令速查(2026 版)
java·大数据·人工智能·git·python·elasticsearch·设计模式
醉颜凉1 分钟前
Elasticsearch 实战:数据自动化清理完全指南(ILM + 定时删除 + 最佳实践)
elasticsearch·自动化·jenkins
2301_816997882 分钟前
性能调优(基于 Elasticsearch 8.x)
大数据·elasticsearch·搜索引擎
易知微EasyV数据可视化1 小时前
数序重构・智启新生|袋鼠云发布Data+AI智能飞轮战略,2026春季发布会圆满落幕
大数据·人工智能·经验分享·数字孪生·空间智能
爱码小白2 小时前
MySQL索引与SQL优化
大数据·数据库·python
智慧医养结合软件开源3 小时前
规范新增·精准赋能,凝聚志愿力量守护老人安康
大数据·安全·百度·微信·云计算
未来之窗软件服务3 小时前
数据库优化(九)随机抽选系统数据表 ——东方仙盟
大数据·数据库·数据库优化·仙盟创梦ide·东方仙盟
b***25113 小时前
动力电池自动生产线的工艺逻辑与运维要点
大数据·人工智能
一切皆是因缘际会3 小时前
本地大模型轻量化部署
大数据·人工智能·机器学习·架构
Snooker_1464 小时前
TRAE、VSCode上进行git管理
ide·git·vscode