gitvue.jsvuejs3vue-cli

Using 'vue create <projectname>', git add . doesn't seem to work


I was creating a new Vue app and used 'vue create testapp'. I selected the typical defaults and it initialized the directory for git. Fine. I changed the directory to the project's directory and typed 'git status', I get the following:

On branch master
nothing to commit, working tree clean

When I did 'git add .', I get the following:

On branch master
nothing to commit, working tree clean

Nothing was added even though the directory contains files:

babel.config.js  jsconfig.json  node_modules/  package.json  package-lock.json  public/  README.md  src/  vue.config.js

If I delete the .git directory and re-run 'git init' git will work properly.

What's wrong? Thank you in advance!


Solution

  • In most projects created using CLI, such as create react app/vue cli, using git means all the contents of the initialized project will be automatically committed once, with init as the commit message.

    This means that we don't need to manually commit for the first time.

    You can use git log to view the history, and there will be a 'init' as the first and only commit.

    If changes are made after initialization, git add will take effect.

    If you are curious about how Vue CLI handles it here, you can refer to the following code: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli/lib/Creator.js#L241-L256

        // commit initial state
        let gitCommitFailed = false
        if (shouldInitGit) {
          await run('git add -A')
          if (isTestOrDebug) {
            await run('git', ['config', 'user.name', 'test'])
            await run('git', ['config', 'user.email', 'test@test.com'])
            await run('git', ['config', 'commit.gpgSign', 'false'])
          }
          const msg = typeof cliOptions.git === 'string' ? cliOptions.git : 'init'
          try {
            await run('git', ['commit', '-m', msg, '--no-verify'])
          } catch (e) {
            gitCommitFailed = true
          }
        }