工作中常用的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

相关推荐
Aurora_th42 分钟前
浙江海洋大学 资料共享 期末考试卷、课程资料等
git·github
AI_Auto1 小时前
中小企业数字化转型指南 | 拆解中小企业数字化四大转型特征
大数据·人工智能·制造
资深低代码开发平台专家1 小时前
2026企业级AI编程平台厂推荐:行业趋势、评估维度与主流品牌对比解析
大数据·人工智能·ai编程
小白说大模型2 小时前
Spring AI 框架中集成 MCP 的完整指南:从服务端到客户端的全流程实践
大数据·数据库·人工智能·安全·spring·chatgpt·开源
HiDev_3 小时前
【非标自动化】2、认识元器件(液压泵和液压阀)
大数据·人工智能·自动化
ZhiMuZhiLing3 小时前
数据驱动的B2B客户画像:行业、规模、时间、地域维度解析
大数据·创业创新·流量运营
晓子文集3 小时前
Tushare接口文档:每日涨跌停价格(stk_limit)
大数据·数据库·金融数据·量化投资
2601_960906724 小时前
全球AI产业正加速迈入全域渗透
elasticsearch·百度·database·时序数据库·memcache
IanSkunk4 小时前
眼视光设备全周期台账:从验收入库到使用效果数据化的管理闭环
大数据·网络·人工智能
拓人间精准客4 小时前
2025–2026 ToB 精准拓客实战手册:用“企业数据画像 + 动态筛选“击穿七大行业获客内卷
大数据·数据库·人工智能