2015-06-19 34 views
0

我試圖暫時取消兩個文件。當I型git的狀態我的信息是:無法使用git將文件從停頓中移走

On branch master 
    Your branch is up-to-date with 'origin/master'. 
    Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    modified: public/javascripts/app.js 
    new file: views/templates/caffeineTable.html 

我使用GIT中復位HEAD和該文件以unstage在命令行上,如圖所示。但是,當我按照說明回到我的分支主人

(use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 
    modified: public/javascripts/app.js 

我跟着第一步,添加了文件進行更新。但是,當我做git狀態時, 。我回到了同樣的起始位置。

我讀過git https://git-scm.com/book/en/v2/Git-Basics-Undoing-Things上的文檔,但不確定是否需要一個git checkout。

目標是讓所有東西都保持最新狀態,並且沒有任何過渡。

回答

2

你需要一些關於git的基本概念。當你在你的第二個步驟:

(use "git add <file>..." to update what will be committed) 
(use "git checkout -- <file>..." to discard changes in working directory) 
    modified: public/javascripts/app.js 

Git是告訴您app.js文件被修改,相對於上一個版本。您的文件(可能)是最新的,但有一些額外的變化。您可以使用

git diff 

顯示它與HEAD版本(=歷史記錄中的最後一個版本)的差異。現在git的爲您提供兩種選擇:

  1. git add:要階段這些變化;那意味着準備這些改變來提交它們並將它們保存在歷史中。
  2. git checkout:你想放棄這些改變; 不能撤銷;您的文件將被替換爲該文件的HEAD版本。