Marchan4
@Marchan4 (Marchan4)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

「git addでワークツリーからインデックスにステージされたsample.txt」をローカルリポジトリにコミットできない理由を教えてください。

使用機器macOS Big Sur バージョン11.2.2です。使用中のテキストエディタはAtomです。

下記のコマンドで(git initというGitコマンド)ローカルリポジトリを作成いたしました。

$ git init

hint: Using 'master' as the name for the initial branch. T
his default branch name
hint: is subject to change. To configure the initial branc
h name to use in all
hint: of your new repositories, which will suppress this w
arning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main'
, 'trunk' and
hint: 'development'. The just-created branch can be rename

d via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /Users/ユーザ名/Do
wnloads/プログラミング関連/kadai-commit/.git/

下記のコマンドはsample.txtがワークツリーに追加されたことを教えております。

$ git status

On branch master


No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be comm
itted)
        sample.txt

nothing added to commit but untracked files present (use "
git add" to track)

下記のコマンドでワークツリーからインデックスに移動させました。

$ git add sample.txt

下記のコマンドはsample.txtがインデックスにあり、次のコミットに入ることを示しております。

$ git status

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   sample.txt

下記の画像では、sample.txtをローカルリポジトリにコミットしようとしてるのですが、コミットメッセージ(add sample.txt)を入力致した後にエンターキーを押しても、sample.txtはローカルリポジトリにはコミットされませんでした。

スクリーンショット 2021-04-18 17.25.44.png

それからもう一度

$ git commit

というコマンドを入力させて頂いたら、下記のエラーが表示されました。

E325: ATTENTION
Found a swap file by the name "~/Downloads/プログラミング関連/kadai-commit/.git/.COMMIT_EDITMSG.swp"
          owned by: ユーザ名   dated: Sun Apr 18 18:01:44 2021
         file name: ~ユーザ名/Downloads/プログラミング関連/kadai-commit/.git/COMMIT_EDITMSG
          modified: YES
         user name: ユーザ名   host name: パソコン名
        process ID: 非公開
While opening file "/Users/ユーザ名/Downloads/プログラミング関連/kadai-commit/.git/COMMIT_EDITMSG"
             dated: Sun Apr 18 18:55:46 2021
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /Users/ユーザ名/Downloads/プログラミング関連/kadai-commit/.git/COMMIT_EDITMSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/ユーザ名/Downloads/プログラミング関連/kadai-commit/.git/.COMMIT_EDITMSG.swp"
    to avoid this message.

Swap file "~/Downloads/プログラミング関連/kadai-commit/.git/.COMMIT_EDITMSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

私は上記の最後の行に書かれてある[O]pen Read-Onlyを選択し、

また下記の画像のようにコミットメッセージを入力致した後にエンターキーを押しても、sample.txtはリモートリポジトリにコミットされませんでした。

スクリーンショット 2021-04-18 17.25.44.png

0

1Answer

コミットメッセージ(add sample.txt)を入力致した後にエンターキーを押しても、sample.txtはローカルリポジトリにはコミットされませんでした。

エンターキーを押しただけではコミットされません。メッセージを入力したらエスケープキーを押して :wq と入力してエンターキーを押してください。

1Like

Comments

  1. @Marchan4

    Questioner

    わかりやすく教えていただきありがとうございました。

Your answer might help someone💌