Git 切换到旧提交,同时保证当前修改不丢失

项目多分支切换,不想提交代码怎么办-- --git stash 如果你在多个分支之间来回切换,并且不提交代码,也不想删除代码,这时git stash是一个有用的工具,但它并不是唯一的解决方案。让我们详细看看git stash。 阅读详情

在 Git 中,可以通过以下几种方式切换到之前的提交,同时保留当前的修改

1. 使用 git checkout 创建临时分离头指针(推荐用于查看代码)

git checkout <commit-hash>

这会让你进入"分离头指针"状态,你可以查看旧代码。要返回最新提交:

git checkout <原来的分支名>

# 返回上一次分支,类似bash的cd -
git checkout -

2. 使用 git branch 创建新分支(最安全)

git branch temp-branch <commit-hash>  # 创建临时分支指向旧提交
git checkout temp-branch              # 切换到临时分支

这样你的原分支和新提交都完好保存,可以在临时分支上操作。

3. 使用 git stash 暂存当前修改(修改未提交)

git stash          # 保存当前工作
git checkout <commit-hash>  # 切换到旧提交
# 查看或操作后...
git checkout -     # 回到原分支
git stash pop      # 恢复暂存的修改

4. 使用 git reset --soft(可逆操作)

如果想在当前分支"回退"到旧提交但保留所有更改在暂存区:

git reset --soft <commit-hash>

之后可以用 git reset ORIG_HEAD 撤销这次回退。

注意事项:

  • 所有方法都不会丢弃提交,只要提交还在 reflog 中(默认保留90天)
  • 要永久丢弃提交需要使用 git reset --hard 或 git push -f(慎用)
  • 推荐优先使用创建新分支的方式,这是最安全的选择

可以通过 git reflog 查看所有历史操作记录,找回"丢失"的提交。

Debezium系列之:详细记录数据库迁移debezium保证数据不丢失的方法和步骤流程 阅读详情

相关推荐

工业相机TEC散热技术:从原理到高精度成像的实战解析

本文深入解析了工业相机TEC散热技术的核心原理与实战应用。通过阐述热电制冷器如何利用帕尔帖效应实现精准温控,有效抑制图像传感器暗电流噪声,从而保障高精度成像的稳定性。文章结合工业场景痛点,提供了从TEC选型、系统集成到控制逻辑的完整设计指南,并分享了不同应用场景下的实战案例,是提升工业视觉系统成像质量的关键技术解析。

weixin_29269441的博客 410

git工作中常用命令

git命令: git config --global user.email “your@email.com” git config --global user.name “yourname” git clone -b 分支名 地址 测试分支:ns_ci_int_qa git pull --rebase origin ns_ci_int_qa 同步远端分支代码 线上分支:dbg_add_pro_biz 1、从线上分支拉取新的分支开发 git add git commit -m “YJ: xxx” gitk

一个刚入行的新人猿 4995

基于ADS1299的8通道脑电采集系统硬件设计实战

生物电信号采集是医疗电子与可穿戴设备中的关键环节,微弱信号的高保真放大与数字化处理直接影响系统性能。高精度模数转换器与低噪声模拟前端设计成为工程实践的核心。ADS1299作为专用生物电测量芯片,集成多通道低噪声放大器与24位Δ-Σ ADC,广泛应用于脑电、心电等生理信号检测。本文基于ADS1299构建8通道脑电采集系统,详细阐述硬件架构、电源与参考设计、输入保护、PCB布局布线、固件SPI配置及数据读取,并结合实测数据分享噪声抑制与调试经验,为EEG采集设备开发提供完整参考。

weixin_29169505的博客 222

git切换分支代码到某一次commit提交

git命令:git reset --hard commit-id可以通过git log输出查找。git reset撤销当前分支所有修改,恢复到最近一次修改前干净的分支情况,首先:git reset --hard接着:git clean -fd。git reset撤销当前分支所有修改,恢复到最近一次修改前干净的分支情况_zhangphil的博客-优快云博客。git回退代码仓库版本_git回退到之前的版本会影响本地代码嘛_zhangphil的博客-优快云博客。

Zhang Phil 4365

保姆级教程:在RK3588平台上为IMX415 Sensor配置HDR2曝光(附完整代码与避坑点)

本文提供RK3588平台上为IMX415 Sensor配置HDR2曝光的详细教程,涵盖基础概念、限制条件、实战配置步骤及常见问题解决方案。通过完整代码示例和关键参数解析,帮助开发者高效实现HDR2曝光模式,提升图像质量并避开常见陷阱。

weixin_28685287的博客 283

DDR5内存命令真值表详解:如何正确解析JESD79-5标准中的关键指令

本文深度解析JESD79-5标准中的DDR5内存命令真值表,将其视为动态通信协议进行拆解。详细阐述了1-Cycle与2-Cycle命令的区别、Bank Group寻址机制以及模式寄存器(MR)操作流程,为硬件与固件工程师提供了从信号解析到系统调试的完整实战指南,是理解和优化高性能计算平台内存子系统的核心。

numpy6sculptor的博客 546

【Git专栏】git如何切换到某个commit(超详细)

本文介绍了如何安全地使用Git将本地代码切换到历史版本,而不会影响远程仓库。主要方法有:1)通过git checkout [commit]临时查看旧版本;2)创建临时分支git checkout -b [branch] [commit]进行修改测试。

欢迎来到兰舟比特的博客! 4588

Open3D 点云数学形态学滤波(Python版本)

Open3D 点云数学形态学滤波(Python版本)

dayuhaitang1的博客 1394

git回退到某个提交

(慎重用,用前最好备份一下代码,或者用git diff 生成一个patch)退到/进到 指定的commit(使用git log查看历史提交信息)//只删除commitID之后的提交记录log,代码的改动还在。//彻底删除commitID之后所做的改动,代码也一起回退回来了。回退到前3次提交之前。

棠樾的博客 6079

LFI Scanner 本地文件包含漏洞扫描、文件路径遍历、敏感文件读取(etcpasswd)

✅ **敏感文件读取验证**:内置`/etc/passwd、/windows/system32/drivers/etc/hosts、phpinfo.php`等敏感文件字典,一键验证漏洞可利用性;🔴 **Windows**:`/windows/win.ini`(系统配置)、`/windows/system32/drivers/etc/hosts`;🔴 **Linux**:`/etc/passwd`(用户信息)、`/proc/version`(内核版本)、`/etc/hosts`(域名解析);

寒寒豆豆软件公司的博客 130

海康visionmaster-渲染结果:通过绑定流程或模块获取 渲染结果的方法

海康visionmaster-渲染结果:通过绑定流程或模块获取 渲染结果的方法

视觉人机器视觉的博客 2635

Git回到某个分支的某次提交

在Git中回到某个分支的某次提交

Amy_cx的博客 2917

JVM高频面试基本问题与知识点整理

JVM高频面试基本问题与知识点整理

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 87万+

git之 分支切换时相互影响的问题,切换分支注意,是否已经提交或stash,否则会互相影响本地分支代码

https://blog.youkuaiyun.com/weixin_34114823/article/details/92254904 1.跳转分支之前git status一下查看是不是有没有add和commit的工作,如果有,可以的话,就都提交掉。(事实上尚未add的工作带到了新分支下如果不继续对该文件进行处理,带过去也是没有影响的,大不了跳回来再带回来嘛,反正木有add过的内容在新分支下c...

u012683752的专栏 4002

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Git Stash用法,方便临时处理bug时随时切换分支而不丢失修改

最近在使用Git管理项目工程的时候,遇到了很多问题,也学习到了很多关于Git常见使用的技巧,下面就其中关于Git Stash的用法和大家分享下。 首先,简单介绍下Git Stash命令的用法,详细的用法在man文档中有相关介绍,下面我来说明常见的使用。 git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到

Tim 1716

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【Git】拉取gerrit上未合入代码本地开发后再提交

同事A在gerrit上提交了一笔代码,未合入,同事B需要基于同事A的代码进行开发,开发完成后作为一个新patch提交到同事A的gerrit链接上。第一笔是同步同事A代码至本地生成的记录,第二笔是同事A提交代码至gerrit生成的记录,第三笔是同事X最新上库的代码记录。其中,commit-id为同事X最新提交记录的commit-id,--soft保证代码不丢失。至此,同事B就能把新开发的代码提交至同事A的gerrit上,形成一个新的patch。

qq_38801607的博客 1380

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

git submodule临时分支;以及git reset使用

submodule 已经建立好了一个gitlab submodule形式的repo: 在repo A下面有一个submodule B, A --> B。 clone -b branch [repoA] cd A git submodule update --init 之后,在B的文件夹下运行 git branch 会发现当前分支处于一个临时分支上: (...

weixin_30654419的博客 1187

git reset命令之谜

1.git reset的目的 (1)git reset操作可以使得当前的分支指向某一个提交。 (2)为了避免丢失本地的修改以及original HEAD,建议在进行reset操作之前,在本地创建一个新的branch,在新的branch上面进行reset,以保证master分支永远处于original HEAD。 2.Definitions 首先,为了讲解git reset的命令之谜,我们先...

u012803336的博客 321

Git 基础命令理解与使用

本文内容,主要来自Learn Git Branching的教程。 包括commit,branch,branch -f,checkout checkout -b,HEAD分离,merge,rebase,reset,HEAD和^~符号,cherry-up,rebase -i,commit --amend,tag,describe,clone,fetch,pull,push,pull source:goal,push source:goal,fetch source:goal,branch -u。

BedwarsXD的博客 1125

git 相关指令

【代码】git 相关指令。

m0_63935762的博客 247

Git Stash——拯救纠结伦的你

文章摘要: Git stash是一个强大的版本控制工具,用于临时保存未提交的代码变更。基础命令包括git stash保存变更、git stash list查看暂存列表、git stash apply/pop恢复变更。常用选项如-u包含未跟踪文件、-m添加描述信息。高级用法支持创建分支应用暂存(git stash branch)。需注意暂存仅限本地、可能产生冲突,建议添加描述信息并定期清理。典型使用场景包括临时切换分支时保存工作进度,通过stash push/pop实现安全的工作状态切换。

qq_34583944的博客 763

显示当前分支下追踪的所以文件_.gitignore明明声明了,为啥切换分支就报错呢...

问题描述:stackoverflow对该问题的描述我在我的.gitignore文件添加了一些文件,这是为了在上传的时候不被commit当我执行git status,git反馈如下:# On branch latest nothing to commit (working directory clean)不管怎样,当我尝试改变分支的时候,我得到这个信息:My-MacBook-Pro:webapp m...

weixin_29176179的博客 190

【devops】devops-git之git分支与标签使用

  一、git分支    1.什么是分支    2.分支的操作     1)查看 当前分支     2)查看所有分支     3)创建分支     4)切换分支     5)使用分支     6)合并分支     7)合并冲突     8)删除分支   二、git标签    1.打标签     1)查看提交     2)打标签     3)给指定提交打标签    2.查看标签    3.根据标签回滚    4.删除标签

zerotoall的博客 1182

git stash/git fetch/git rebase/git cherry pick/git reset

回到刚才执行gitstash的分支,执行gitstashpop,就会将最近一次藏起来的内容提取出来了。(注如果stash了好几次,要提取其中某一次的内容,可以使用````gitstashapply``命令)原因gitpull要更新代码时本地代码修改了需要先commit或stash但是不想commit就可以stash保证本地工作区干净。StashChanges相当于gitstash,将选中的变更文件“藏起来”,然后当前分支就“干净”了,可以切换到其他分支去了。.....................

sueong的博客 593
上一篇: 1.1 安装编译环境
下一篇: 1.2 编译基础知识
卖猪肉的痴汉
博客等级 码龄10年 166粉丝 82原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值