Error pathspec first commit did not match any file s known to git

Not sure if I am doing something wrong here. Just testing the commit task at this point. In a new project I do git init and git add . in the cli. git status shows files ready to be commited. So I r...

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account


Closed

isimmons opened this issue

Feb 12, 2014

· 15 comments

Comments

@isimmons

Not sure if I am doing something wrong here. Just testing the commit task at this point.

In a new project I do git init and git add . in the cli. git status shows files ready to be commited.

So I run gulp commit and get the following errors

λ gulp commit
[gulp] Using file C:Userslotusprojectsgulpjscsgulpfile.js
[gulp] Working directory changed to C:Userslotusprojectsgulpjscs
[gulp] Running 'commit'...
[gulp] Finished 'commit' in 4.79 ms
[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp]  error: pathspec 'commit'' did not match any file(s) known to git.

[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp]  error: pathspec 'commit'' did not match any file(s) known to git.

[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
error: pathspec 'node_modules' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp]  error: pathspec 'commit'' did not match any file(s) known to git.
error: pathspec 'node_modules' did not match any file(s) known to git.

[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp]  error: pathspec 'commit'' did not match any file(s) known to git.

Here is the task

// Run git commit
gulp.task('commit', function(){
    gulp.src('./*')
        .pipe(git.commit('initial commit'));
});

This is on Windows in case that has anything to do with it.

@stevelacy

Can you enter the node_modules/gulp-git/lib and edit commit.js with the following?

Right directly under line 12:

 var cmd = "git commit -m " + escape([message, file.path]) + " " + opt.args;

Add this:

And post the results from the gulp log here?
It may be the UNIX vs win characters escaped in shell-escape

@isimmons

Was just doing that :-)

The result is

git commit -m 'initial commit' C:Userslotusprojectsgulpjscsgulpfile.js

Copy/pasting that in the cli gives me the same message but it works if I use double quotes around the message

git commit -m "initial commit" C:Userslotusprojectsgulpjscsgulpfile.js

@stevelacy

Ah yes!
I now remember that the time (only time ;) ) I was using git on windows I Needed to use the double quotes.
I will need to manually add that in instead of using shell-escape, I hope to get it done shortly.
Thanks for noticing it.

@isimmons

Thanks. And thanks for your work already building this.

@stevelacy

Can you check to see if my latest publish fixed it?

@stevelacy

@isimmons

So sorry I got off doing other things and didn’t realize you had replied back. Yes I will definitely check it in the morning.

@isimmons

Not working for me. Something with the file.cwd now. I added a console.log( cmd, file.cwd); at line 13 in commit.js . Here is what I get.

λ gulp commit
[gulp] Using file C:Userslotusprojectsgulpgittestgulpfile.js
[gulp] Working directory changed to C:Userslotusprojectsgulpgittest
[gulp] Running 'commit'...
[gulp] Finished 'commit' in 4.7 ms
git commit -m "initial commit" $'C:\Users\lotus\projects\repo\anothertest.txt'  C:Userslotusprojectsgulpgittest
git commit -m "initial commit" $'C:\Users\lotus\projects\repo\testfile.txt'  C:Userslotusprojectsgulpgittest
[gulp] { [Error: Command failed: fatal: Not a git repository (or any of the parent directories): .git
] killed: false, code: 128, signal: null }
[gulp]  fatal: Not a git repository (or any of the parent directories): .git

[gulp] { [Error: Command failed: fatal: Not a git repository (or any of the parent directories): .git
] killed: false, code: 128, signal: null }
[gulp]  fatal: Not a git repository (or any of the parent directories): .git

Here’s the task

gulp.task('commit', function() {
    gulp.src('../repo/*')
        .pipe(git.commit('initial commit', {}));
});

@stevelacy

Did you run git init in the other dir, or this one?

Windows may only allow in path git. Such as the git folder in local ./

@isimmons

I made a directory ‘repo’ next to ‘gulpgittest’

Then in repo

git init
touch testfile.txt
git add .
git commit -m "manually running git commands'

git repo is initialized and testfile.txt added and commited correctly

Then

touch anothertestfile.txt
git add .
git status //shows file added and ready for commit
cd ../gulpgittest
gulp commit

Am I misunderstanding? I’m thinking file.cwd should be

C:Userslotusprojectsrepo

But instead it is the same directory the gulpfile is running from (same as cwd)

C:Userslotusprojectsgulpgittest

@isimmons

If I initialize a git repo inside gulpgittest it tells me the file is outside the repo so it is trying to run git commit in the local ./

I may be misunderstanding the purpose of this plugin. Is it intended to be inside the actual repo? I was thinking I could use it to run git commands on another directory. That way I could copy files from this directory to a separate repo and then run the git commands on that repo without leaving this directory. That way it can be used as part of a deploy process where the actual repo is outside the project.

@stevelacy

I will look into the issue, it is designed to allow any folder and look for git from that files cwd, not just the local.
Unless I need to monkey patch it for windows…

@isimmons

Ok, I’ll keep messing around with it and let you know if I figure out anything. Thanks

@stevelacy

Can you confirm that #7 works for you?

@stevelacy

2 participants

@isimmons

@stevelacy

Scenarios that emerge

In the local init, a repository is created, and then a develop ment branch is created, on which file operations are performed, followed by changes made by commit.

$ git init
Initialized empty Git repository in D:/practice/testBranch/.git/
$ git checkout -b develop
Switched to a new branch 'develop'
$ vim a.txt
$ git add a.txt
$ git commit -m "add a new file"
[develop (root-commit) f9ac3b8] add a new file
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt

Then you cut to the master branch and do the file operation. Then the following mistakes will occur:

$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

Reasons for the problem

Command parsing

The git init command creates a master branch by default and points the HEAD (which is a special pointer to the current local branch) to that branch. Nevertheless, you can’t see any branches when you view local and remote branches through the GIT branch-a command.
The git checkout master command actually does two things: one is to make HEAD refer back to the master branch; the other is to restore the working directory to the snapshot content that the master branch refers to.

problem analysis

After HEAD refers back to the master branch, it is necessary to restore the working directory to the content that the master branch refers to. But since you’ve been working on the develop ment branch since the beginning, the working directory corresponding to the master branch is equivalent to nothing, so that no files can be matched.

How to solve

You just need to initialize a repository, first do some commit operations on the master branch, such as adding a README.md file, so that you really create a master branch. For example:

$ git init
Reinitialized existing Git repository in D:/practice/testBranch/.git/
$ vim README.md
$ git add README.md
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.
$ git commit -m "add a new file"
[master (root-commit) 0e8c7c3] add a new file
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/benben/testBranch/pull/new/master
remote:
To github.com:benben/testBranch.git
 * [new branch]      master -> master

When push ing, you can see the prompt to create a master branch in the remote warehouse, and the local master branch points to the remote master branch.
Then you can see all local and remote branches through git branch-a. Then you can create other branches and switch between master branches at will.

$ git branch -a
* master
  remotes/origin/master

When switching branches, be aware that the files in your working directory will be changed. If you switch to an older branch, your working directory will be restored to what it looked like when it was last submitted. If Git can’t do this cleanly, it will prohibit branch switching.

Maria Yudina

Maria Yudina

Posted on Nov 14, 2021

• Updated on Dec 3, 2022

Sometimes after repository checkout you can encounter the error trying to switch branches:

git checkout branch_name
error: pathspec 'branch_name' did not match any file(s) known to git

Enter fullscreen mode

Exit fullscreen mode

To fix that you can remove remote origin and link it again.
First, check the remote origin:

git remote -v
origin  git@github.com:company/project_name (fetch)
origin  git@github.com:company/project_name (push)

Enter fullscreen mode

Exit fullscreen mode

Then remove origin:

git remote remove origin

Enter fullscreen mode

Exit fullscreen mode

And add remote origin again with correct path from your repository (copy from GitHub/GitLab/etc.):

git remote add origin git@github.com:company/project_name.git

Enter fullscreen mode

Exit fullscreen mode

After that run:

git pull --ff-only

Enter fullscreen mode

Exit fullscreen mode

And set upstream to origin branch:

git branch --set-upstream-to=origin/current_branch

Enter fullscreen mode

Exit fullscreen mode

After this you should be able to switch between the branches as usual.

This error message indicates that Git was unable to checkout the specified branch because it does not exist. This can happen for a few different reasons, including the following:

  • The branch name is misspelled or mistyped.
  • The branch has already been deleted or is no longer available.
  • The branch exists in a remote repository, but it has not yet been pulled or fetched to the local repository.

To fix this error, you will need to verify that the branch name is correct and that the branch exists in the local repository. If the branch name is correct and the branch still does not exist, you may need to pull or fetch the branch from the remote repository where it exists.

If the branch has already been deleted or is no longer available, you will need to create a new branch with a different name or switch to a different existing branch.

Overall, this error can be resolved by checking the branch name and ensuring that the branch exists in the local repository. If necessary, you can also try pulling or fetching the branch from the remote repository where it exists.

Понравилась статья? Поделить с друзьями:
  • Error passphrase chosen is below the length requirements of the usm min 8
  • Error passing const as this argument discards qualifiers
  • Error partition table is empty
  • Error parsing xml unbound prefix error
  • Error parsing uri scheme must be mongodb or mongodb srv