博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使用Git Pull覆盖本地文件
阅读量:2524 次
发布时间:2019-05-11

本文共 2145 字,大约阅读时间需要 7 分钟。

什么时候需要覆盖本地文件? (When do you need to overwrite local files?)

If you feel the need to discard all your local changes and just reset/overwrite everything with a copy from the remote branch, then you should follow this guide.

如果您需要放弃所有本地更改,而只是使用远程分支的副本重置/覆盖所有内容,则应遵循本指南。

Important: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven’t been pushed will be lost.

重要提示:如果您进行任何本地更改,它们将会丢失。 无论是否使用--hard选项,所有尚未推送的本地提交都将丢失。

If you have any files that are not tracked by Git (e.g. uploaded user content), these files will not be affected.

如果您有Git不能跟踪的任何文件(例如,上载的用户内容),这些文件将不会受到影响。

覆盖工作流程: (The Overwrite workflow:)

To overwrite your local files do:

要覆盖本地文件,请执行以下操作:

git fetch --allgit reset --hard 
/

For example:

例如:

git fetch --allgit reset --hard origin/master

这个怎么运作: (How it works:)

git fetch downloads the latest from remote without trying to merge or rebase anything.

git fetch从远程下载最新版本,而无需尝试合并或重新设置任何内容。

Then the git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master.

然后git reset将master分支重置为您刚获取的分支。 --hard选项更改工作树中的所有文件,以匹配origin/master中的文件。

附加信息: (Additional Information:)

It’s worth noting that it is possible to maintain current local commits by creating a branch from master or whichever branch you want to work on before resetting:

值得注意的是,可以通过在重置之前从master或您要处理的任何分支创建分支来维护当前的本地提交:

For Example:

例如:

git checkout mastergit branch new-branch-to-save-current-commitsgit fetch --allgit reset --hard origin/master

After this, all of the old commits will be kept in new-branch-to-save-current-commits. Uncommitted changes however (even staged), will be lost. Make sure to stash and commit anything you need.

在此之后,所有旧提交都将保存在new-branch-to-save-current-commits 。 但是,未提交的更改(即使已分阶段)将丢失。 确保隐藏并提交您需要的任何东西。

归因: (Attribution:)

This article is based on a Stack Overflow question <a href=’’ target=’blank’ rel=‘nofollow’>here_

本文基于堆栈溢出问题<a href =' ://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull/8888015#8888015'target ='空白'rel ='nofollow'>此处_

翻译自:

转载地址:http://iozzd.baihongyu.com/

你可能感兴趣的文章
jQuery 解决 IE 6/7/8 BUG:下拉框select设宽度时option超出显示不全
查看>>
15 个有趣的 JavaScript 与 CSS 库
查看>>
实现iOS语言本地化/国际化
查看>>
ASP.NET MVC学习---(二)EF文件结构
查看>>
年会-2014
查看>>
MBTIles实现
查看>>
创建WPF项目
查看>>
电源模块的PCB设计
查看>>
光猫与普通的家用猫
查看>>
Asp.Net 构架(Http Handler 介绍) - Part.2
查看>>
6.11 spring框架
查看>>
charles抓包--手机端
查看>>
hdu 5018
查看>>
Python--eval()函数
查看>>
【转载】Linux下的crontab定时执行任务命令
查看>>
STM32 HAL库的定时器中断回调函数跟串口中断回调函数
查看>>
vs2010找不到ado.net 实体数据模型解决办法
查看>>
(转)深入理解javascript连续赋值表达式
查看>>
用户场景分析
查看>>
几种分布式锁的实现方式
查看>>