``git重置 - hard'对我的改变?

技术标签: git  版本控制

我有一个设置(需要这种方式),在其中我将更新的文件同步到git存储库。当文件更改时,这会发生 .git 在此同步过程中忽略了文件夹。

所以

  • 客户端(带有回购结帐)>文件同步(忽略.git)>服务器(带回购结帐)
  • 客户>上游git回购(不时)
  • 上游Git Repo>服务器(不时)

有时,我需要更新git server 基于上游,所以我正在使用 git fetch --all && git reset --hard origin/branchname。哪个为此目的工作。

但是,我希望能够检测到是否实际更新任何文件。换句话说,如果客户端文件同步与上游Git Repo最新,我想检测到。

我能找到的最接近的方法是答案 这里 正在使用类似的东西 git merge-tree $(git merge-base FETCH_HEAD master) FETCH_HEAD master。问题在于它显示了更改,即使文件和内容已经存在...

使用测试柜更新

$ { ~/repos }$ mkdir a && cd a

$ { ~/repos/a }$ git init
Initialized empty Git repository in ~/repos/a/.git/

$ { ~/repos/a }$ echo file1 > f1 && git add f1 && git commit -m "1"
[master (root-commit) 9b1b025] ..
 1 file changed, 1 insertion(+)
 create mode 100644 f1

$ { ~/repos }$ git clone a b
Cloning into 'b'...
done.

$ { ~/repos }$ cd b

$ { ~/repos/b }$ ls
f1

$ { ~/repos/a }$ echo file2 > f2 && git add f2 && git commit -m "2"
[master 4e40da5] 2
 1 file changed, 1 insertion(+)
 create mode 100644 f2

$ { ~/repos/b }$ git fetch --all
Fetching origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ~/repos/a
   9b1b025..4e40da5  master     -> origin/master

# The folder `b` started with 1 file `f1`, and it can now
# see the new file `f2` as expected.
$ { ~/repos/b }$ git diff HEAD..origin/master
diff --git a/f2 b/f2
new file mode 100644
index 0000000..6c493ff
--- /dev/null
+++ b/f2
@@ -0,0 +1 @@
+file2

# Without using git (another file sync job, think rsync),
# the `f2` is created identical, but without informing git.
# After this, the repos contains the exact same data,
# but git doesn't know that.
$ { ~/repos/b }$ echo file2 > f2

# However, git diff still thinks this file is new..
# At this point, I want to be able to see if
# the origin/master is identical to the content of this repository.
$ { ~/repos/b }$ git diff HEAD..origin/master
diff --git a/f2 b/f2
new file mode 100644
index 0000000..6c493ff
--- /dev/null
+++ b/f2
@@ -0,0 +1 @@
+file2

# Untill I do a reset --hard
$ { ~/repos/b }$ git reset --hard origin/master
HEAD is now at 4e40da5 2

# Doesn't show any output
$ { ~/repos/b }$ git diff HEAD..origin/master

看答案

你可以看到 diff 之间 origin/masterHEADreset.

$ git fetch --all
$ git diff HEAD..origin/master        # see what is in origin/master that is not in HEAD (local latest commit)

$ git diff origin/master..HEAD        # see what is in HEAD that is not in origin/master

# If local uncommitted changes exist (tracked by git)
$ git diff origin/master

# for untracked/new files, one way is to use '-N' flag with 'git add' command
$ git add -N .
$ git diff origin/master

有关“ -n”的更多信息: $ git add --help

  -N, --intent-to-add
       Record only the fact that the path will be added later. An entry for the path
       is placed in the index with no content. This is useful for, among other
       things, showing the unstaged content of such files with git diff and
       committing them with git commit -a.

智能推荐

git reset --soft, mixed, hard的区别

git reset --soft 撤销最后一次的git commit, 返回的是上一次提交后的修改后的git add后的结果, git reset --mixed git reset的默认参数, 撤销最后一次的git commit和git add, 返回的是上一次提交后的修改后的还未git add后的结果。git reset --mixed相当于git reset --soft后加上git res...

git reset --hard --soft 与 git revert 的作用

1、git reset --hard --soft 与 git revert 的作用: 文件从暂存区回退到工作区 版本回退 2、git简单的分为三个区域 : 1、工作区(working directory) 2、暂缓区(stage index) 3、历史记录区(history) git reset --hard xxx hard (修改版本库,修改暂存区,修改工作区) –hard HE...

git的reset重置:记录一次一键替换全部内容的作死事件和解决办法

事件起始原因: 由于后端和其他同事在给参数取名的时候。 全是小写。 我看着不舒服。 于是想全部改成小驼峰。 于是不仅仅是一键替换。 然后还有手动改写了很多个名称。 不仅把自己的代码改错了。把同事的代码也改错了、 然后就是一直找各种办法改错、耗时2天。也不是2个全天。 不过对于我这个菜鸟来说。非常谨慎。经历过教训后。不敢随意再次乱改。免得错上加错。 最后我们在其他建的项目里面。先练手了。成功之后才在...

git ssh**创建和重置

git项目平时使用好好的,然后出现了这样的错误,应该是SSH哪里出问题了,只好进行SSH重置,于是查了下资料,使用了这篇文章后面的重置方法解决了问题。 为什么配置SHH呢?是为了方便我们剪切代码的时间免密码输入,特别方便如何配置呢? 首先安装git: 先到官网下载:官网下载git 然后安装后在桌面任意空白处右击,选择Git Base Here即可如下图: 在弹出的窗口 1.输入:cd ~/.ssh...

Git 命令之回滚与重置

本文导读 本文仍然以学习Git命令为主,承接《Git开发入门之一》 项目回滚 开发中会出现对一些文件内容修改后,觉得并不满意、或者不小心改错了文件等等 这个时候使用 "git checkout -- xxx" 就能轻松的将内容进行回滚到之前的状态,xxx表示待回滚的文件名 注意:使用了"git add"后添加到了暂存区的文件无法再回滚 从上面的&q...

猜你喜欢

Git ssh**创建、重置和配置

1.鼠标右键打开Git Base Here如图: 2.指令输入 在弹出的窗口 输入:cd ~/.ssh ;回车 然后输入ls查看秘钥列表:回车 如上图是已经配置过了就无需配置。如果没有看到id_ras.pub文件即没有配置,然后请看下面如何配置。对于未配置的,采用以下方式进行配置: git创建** $ cd ~ $ ssh-******.exe 三次回车 打开对应目录的 id_rsa.pub 文件...

《精通git》笔记之九(重置揭密)

三棵树 理解 reset 和 checkout 的最简方法,就是以 Git 的思维框架(将其作为内容管理器)来管理三棵不同的树。“树” 在我们这里的实际意思是 “文件的集合”,而不是指特定的数据结构。(在某些情况下索引看起来并不像一棵树,不过我们现在的目的是用简单的方式思考它。)Git 作为一个系统,是以它的一般操作来管理并操纵这三棵树的: 树 用途...

The Design of Everyday Things 读书笔记

  近日抽闲读了老师推荐已久的这部设计史上的著作——唐纳德诺曼的The Design of Everyday Things,中文译名是《设计心理学》,全套共四部,我读了第一部,总的感觉就一个词——恍然大悟!被作者的细心以及擅于思考所折服,他能够抓住生活中很多人习以为常的不方便和小错误,从而解释糟糕的设计可能带给我们的麻烦甚至灾难。...

博客,记录一点一滴,终将汇聚成星辰大海

博客,记录一点一滴,终将汇聚成星辰大海 目录 写博客的好处: 要怎么写博客: 写博客的好处: 【1】我认为写博客能充当自己的资料库,你能随时翻阅你之前学的所有东西,你是否有这样的经历,明明自己之前学过这方面的内容,而且还挺熟悉,但怎么都记不起来具体细节,这时候你的资料库就能最快帮你回忆起你学的东西。 【2】把自己学到的经验,分享出来,自己之前踩到的所有坑都记录下来,当读者读你的博客时,就能少走一些...

一个好玩的工具BeEF介绍及未来要实验

beef BeEF-XSS是一款非常强大的web框架攻击平台,集成了许多payload,可以实现许多功能 BeEF-XSS可以说是最强大的XSS漏洞利用工具,可以收集浏览器信息、键盘记录、社会工程等 总之就是使用beef这个工具来利用xss漏洞的 beef安装 我在kail虚拟机上安装的,很简单的在终端输入一句命令sudo apt setup beef-xss,然后安装成功设置密码就行了,因为之后...

问答精选

Applying stats.percentileofscore to every row by column

df= I need a new column with the percentile score for each element with respect to the column. The final answer should look like this. I want the output of the stats.percentileofscore() function to be...

C - Creating node with multiple children by function - segmentation fault

I want to create tree with multiple children and create every node with a function. Here is my structure for node: And here is my function to create new node (with four children): When I run this func...

How to get all secrets in one call Azure key vault

I am using sample code explain here https://github.com/Azure-Samples/app-service-msi-keyvault-dotnet but they only explained how can we get single secrete not list of secrete. so to get all secrete I'...

increase eclipse IDE font size

I am using Eclipse I would like to increase the font size of the IDE, not just the font of the editor. Is there any way I can do that? I haven't been able to find a solution for this yet. you can try ...

Generating Guid by database automatically

It regards Entity Framework 6 but maybe it isn’t related to the version. I have some class which has Guid Id but by inheritance. Right now I would like to change this model to auto generate Id b...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答