2015-12-21 67 views
0

如果我刪除目錄.git下的HEADFETCH_HEAD會發生什麼?如果我在.git下刪除HEAD和FETCH_HEAD將會發生什麼

我確實刪除了這些文件,並對README.txt進行了一些更改,嘗試了拉和推(不創建任何分支)。它運行良好。
如果我做更嚴肅的事情,它會產生問題嗎?像重新設置和重置?

Git如何保持跟蹤我正在使用的當前分支?我認爲HEADFETCH_HEAD應該表示這些事情。 .git下的所有文件和目錄是什麼,我可以刪除,但仍然會繼續工作?

換句話說,根據.git,git在本地工作和遠程完美工作必不可少?

$ pwd 
/home/arulmozhi/_/remote-repo/.git 
$ rm HEAD 
$ cd .. 
$ git pull 
Already up-to-date. 

$ cat README.md 
this stuff is from dummy branch 
First file in repo which is to be synced across multiple remotes - gitlab and github 

$ emacs -nw README.md 

$ git commit -am "what happens when we rename/delete .git/HEAD" 
[master 34d647b] what happens when we rename/delete .git/HEAD 
1 file changed, 2 insertions(+), 1 deletion(-) 

$ git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 

nothing to commit, working directory clean 

$ git push 
Counting objects: 7, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (3/3), done. 
Writing objects: 100% (4/4), 401 bytes | 0 bytes/s, done. 
Total 4 (delta 2), reused 0 (delta 0) 
To [email protected]:remote-repo/remote-repo.git 
    fa76250..34d647b master -> master 

$ uname -arn 
Linux koparakesari 3.19.0-31-generiC#36~14.04.1-Ubuntu SMP Thu Oct 8 10:21:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux 
$ ls -1 .git 
branches 
COMMIT_EDITMSG 
config 
description 
hooks 
index 
info 
logs 
objects 
packed-refs 
refs 
+3

如果你想讓所有的東西都能夠完美地工作,假設你不應該碰自己的'.git'。任何完全記錄任何手動更改結果的答案對於堆棧溢出來說都太廣泛了。 – chepner

+0

這意味着你必須在'/ home/arulmozhi/_'或'/ home/arulmozhi'中有另一個.git文件夾:'remote-repo'文件夾可以是一個嵌套的git倉庫。 – VonC

回答

0

我只是刪除HEAD,才 「製造問題」(GIT 2.6.4):

C:\Users\VonC\prog\git\test>rm .git\HEAD 

C:\Users\VonC\prog\git\test>git st 
fatal: Not a git repository (or any of the parent directories): .git 

我不得不恢復HEAD(ref: refs/heads/master)的含量,以使回購再次得到認可。

FETCH_HEAD另一方面,在下一個git fetch再生。

+0

在Ubuntu中它並沒有造成問題... – vanangamudi

+0

@vanangamudi如果你刪除'HEAD'你不再有一個git倉庫(按照定義)。我想,這是否有問題留給讀者看。 –

0

在Ubuntu:

$ git init 
Initialized empty Git repository in /test/.git/ 
$ git status 
On branch master 
... 
$ rm .git/HEAD 
$ git status 
fatal: Not a git repository (or any parent up to mount point /home) 
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). 

所以,顯然出現了一些在無法重現您的測試情況不同。

相關問題