Github

製作 Git 倉庫

  • December 15, 2014

我已經安裝了 git 版本 2.2,但我不能在我的目錄上執行“git stash”和“git pull”。執行 git stash 和 git pull 時出現以下錯誤消息

fatal: Not a git repository (or any of the parent directories):

任何人都可以幫助如何將我的工作目錄作為 git 儲存庫嗎?

根據您的評論,問題只是您尚未在目錄中初始化 git 儲存庫。

Git 將數據和元數據.git儲存在目錄中,儲存在 git 儲存庫的頂層。如果儲存庫尚未初始化,則沒有git stash可以將文件還原到的“乾淨狀態”。您需要創建儲存庫,然後進行送出,然後才能儲存後續更改。

由於您似乎對 git 很陌生,因此我強烈建議您遠離 ‘stash’ 並在需要將更改藏在某個地方時保持對單獨分支的送出。藏匿處變得凌亂,快速。

mkdir mygit || exit -1
cd mygit
git init 
date > file.txt
git add file.txt
git commit -m 'My initial commit'
date >> file.txt
git status
git diff
git stash
git status 
git diff
cd ..
rm -rf mygit

這是一個直接來自外殼的範例:

$ mkdir mygit || exit -1
$ cd mygit
$ git init
Initialized empty Git repository in /Users/dfarrell/mygit/.git/
$ date > file.txt
$ git add file.txt
$ git commit -m 'My initial commit'
[master (root-commit) 21de065] My initial commit
1 file changed, 1 insertion(+)
create mode 100644 file.txt
$ date >> file.txt
$ git status
On branch master
Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)

   modified:   file.txt

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/file.txt b/file.txt
index 99e9a80..8dcda34 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1,2 @@
Mon Dec 15 16:00:32 CST 2014
+Mon Dec 15 16:00:32 CST 2014
$ git stash
Saved working directory and index state WIP on master: 21de065 My initial commit
HEAD is now at 21de065 My initial commit
$ git status
On branch master
nothing to commit, working directory clean
$ git diff
$ cd ..
$ rm -rf mygit
$

引用自:https://serverfault.com/questions/652787