我有一个设置(它需要这样),我正在同步更新的文件到git存储库。这发生在文件更改时,并且在此同步过程中忽略.git
文件夹。`git reset --hard`会为我改变吗?
所以
- 客户机(与回购结帐)>文件同步(忽略的.git)>服务器(带有回购结帐)
- 客户>上游git仓库(不时)
- 上游git仓库>服务器(从时间到时间)
有些时候,我需要基于上游上server
更新GIT中,所以我使用git fetch --all && git reset --hard origin/branchname
。哪些工作为此目的。
但是,我希望能够检测到,如果这实际上更新任何文件或没有。 换句话说,如果客户端文件同步是最新的,与上游混帐回购协议,我想检测吧..
要做到这一点,因为我能找到的最接近的方式是一个答案here这是使用类似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
所以......你想知道'origin/branchname'与'branchname'不同吗?那不就是'git diff branchname origin/branchname'吗?我错过了关于这个问题的东西......? –
请注意,'git reset --hard'会重置索引和工作树中存储的文件(无论出自所选提交的文件),因此如果您的文件与任何提交中的文件不同,那么这些文件也会得到改变。 – torek