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

相关推荐
东哥说-MES|从入门到精通13 分钟前
GenAI-生成式人工智能在工业制造中的应用
大数据·人工智能·智能制造·数字化·数字化转型·mes
万岳软件开发小城41 分钟前
教育APP/小程序开发标准版图:课程、题库、直播、学习一站式梳理
大数据·php·uniapp·在线教育系统源码·教育app开发·教育软件开发
Violet_YSWY2 小时前
git stash和backup一样吗
git
STLearner2 小时前
AI论文速读 | U-Cast:学习高维时间序列预测的层次结构
大数据·论文阅读·人工智能·深度学习·学习·机器学习·数据挖掘
数字化顾问2 小时前
(65页PPT)大型集团物料主数据管理系统建设规划方案(附下载方式)
大数据·运维·人工智能
老蒋新思维3 小时前
创客匠人 2025 全球创始人 IP+AI 万人高峰论坛:AI 赋能下知识变现与 IP 变现的实践沉淀与行业启示
大数据·人工智能·网络协议·tcp/ip·重构·创始人ip·创客匠人
河南博为智能科技有限公司4 小时前
高集成度国产八串口联网服务器:工业级多设备联网解决方案
大数据·运维·服务器·数据库·人工智能·物联网
无代码专家6 小时前
设备巡检数字化解决方案:构建高效闭环管理体系
java·大数据·人工智能
天远数科6 小时前
Node.js 原生加密指南:详解 Crypto 模块对接天远银行卡黑名单接口
大数据·api
expect7g6 小时前
Paimon Branch --- 流批一体化之二
大数据·后端·flink