This command works in git 2.30.0.windows.1 through the Windows 'command' shell.
git checkout [commit hash] -- */migrations/*
It doesn't work with Mate terminal or bash (git 2.17). The problem is that they substitute the present content of the directories */migrations/* (which are empty or don't have the files that were present at the commit I want to pull them from). Mate terminal does this whether I single or double quote.
If I invoke Bash and then, at the new command line, add single or double quotes, git says that it doesn't have any files literally called */migrations/*:
error: pathspec '*/migrations/*' did not match any files known to git
I can get the content of the migrations files if I substitute directories one at a time, but there are 20+ folders of migrations and I assume I have just missed a bit of lore about how to get what I want from a Linux terminal. Can anyone suggest what I ought to be doing?
This */migrations/* syntax is referring to nowhere path. Neither root nor current working directory.
Try these with ls command before checkout with git:
*migrations/*
./*migrations/*
$PWD/migrations/*
And if you got the right output with ls then apply it to git checkout ...
Test 1
ls */tmp/*
ls: cannot access '*/tmp/*': No such file or directory
Test 2
ls /tmp/*
it has output ...
it has output ...
Related
I am trying to do a regression test of my code using git and a bash script.
So I have written a script to run a sample with the current version and with some previous version.
The source files are located in the src directory, and samples are in the samples directory.
Both the src and samples directories are tracked by git under the same project.
I want to roll back only src files and not touch files in samples.
I have tried git reset and git checkout.
Problem:
When I go to src in terminal and type:
git checkout -- *.F90
It does what is should - it changes only Fortran files in this directory.
If I do the same command in a bash script, it changes everything: files in src and in samples! Like if it is run from the main directory, as git checkout or git reset origin/master... How can it be?
Somewhere I have found suggestion to use env -i in a script, but it did not work either.
The whole script is about 500 lines, here is the git related part:
cd $dsrc # go to src directory
ls # debuging, just to see , that I am there
git stash
git checkout origin/master -- *.F90
with the ls command I do see the source files, so I know I am in the right place.
Any ideas?
From the Git glossary for "pathspec":
[...] in particular, * and ? can match directory separators.
So *.F90 matches all .F90 files everywhere. To limit to the current directory, you could use
git checkout origin/master -- "$PWD"/*.F90
Notice that (as pointed out by torek in their comment) the manual refers to what Git does. If the shell can expand the glob first, it will – for example, if there are files in the current directory that do match *.F90.
Only when there aren't any will Git get the unexpanded literal *.F90 and match the * with any prefix, including /. To prevent expansion by the shell, you could quote the glob:
git checkout origin/master -- "$PWD/*.F90"
or use . in the pathspec:
git checkout origin/master -- ./*.F90
I want to rename a directory versioned by Git on a Windows system (change the case of the directory name):
$ git mv docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied
I've also tried with the force-option - but with the same result:
$ git mv --force docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied
For some reason Git fails because it thinks DOCS already is an existing directory and the directory should be moved inside it. I know that I can rename & commit using a temporary directory name and then rename & amend-commit to the final name, but isn't there a way to tell Git that I don't want to move inside any other directory?
You can try to do it in 2 step.
$ git mv docs DOCS2
$ git mv DOCS2 DOCS
it will work
I have tried to rename my directory with TortoiseGit using rename, command prompt using git mv, and git bash using git mv. The move command was either mv Status status or git mv Status status2 and both of them respond "failed: Permission denied". So it seems I am either going to have to delete the git repository and create a new one with the new directory name structure or I am going to have to create a Linux VM, clone it down, and try to rename name it there. It seems only files can be renamed under windows, but directories just fail. As for people that say git mv works for them, there has to be something missing in your setup.
Since windows iד case sensitive you cant rename the file to the same letters. (Docs == docs [ignored case])
You can do it from git bash since git bash is cygwin and its case sensitive since its a unix emulator.
The command is git mv
git mv <old name> <new name>
Here is a demo from git bash. (windows 7)
No. There isn't a way to tell Git that you don't want to move the folder inside any other directory.
This is not a limitation of git, but rather a limitation of Windows and NTFS. Because the filesystem is case-insensitive, it reports that the case-changed new name already exists, which causes the behaviour that you encounter. Try a 2 step rename (with a temporary name), then commit, or changing it on a non-windows (technically on a case-sensitive filesytem) computer.
I'm running Windows 7, and I have the latest version of git (2.7.2.windows.1). I previously used Windows PowerShell as my terminal for git operations, with no issues. Recently, I decided to switch to Git Bash, but I'm having one major issue.
My project has a directory (within which are many subdirectories) whose name is simply an underscore. Whenever I try to run git diff on a file within that directory, I get the following error:
$ git diff _/css/templates/jquery.tag-editor.css
fatal: Invalid object name '_C'.
As far as I know, an underscore is a perfectly valid character in a file/directory name, and tab completion works fine within that directory, so I know the terminal can "see" inside it. Additionally, other contributors to the project, all of them running OSX, do not have this problem. And when I run a simple git diff, without specifying any single file, it works fine, and happily includes the diff for any changed files within the underscore directory. It also works if I cd into the underscore directory and run the git diff from there, so that the path I pass to it does not include the underscore.
What exactly is happening here to prevent me from running git diff on these files? And where does the "C" come from in the error message when I try to do so?
Update
When I run git checkout -- _/css/templates/jquery.tag-editor.css to discard the changes to that file, this is the error I see:
error: pathspec '_C:/Program Files/Git/css/templates/jquery.tag-editor.css' did not match any file(s) known to git.
C:\Program Files\Git is directory of my Git installation. So apparently part of the path is being interpreted as referring to the Git installation directory? Again, what is causing this to happen?
The problems you are experiencing are based on the Posix Path conversions of MinGW/Msys2.
on git-bash try to double a slash: git diff _//css/templates/jquery.tag-editor.css or use backslashes (which need to be escaped in git-bash): git diff _\\css\\templates\\jquery.tag-editor.css or prepend MSYS_NO_PATHCONV=1: MSYS_NO_PATHCONV=1 git diff _/css/templates/jquery.tag-editor.css
on CMD you should use a backslash instead of a slash: git diff _\css\templates\jquery.tag-editor.css OR double a slash as for git-bash
in order to prevent the conversion.
Using git svn fetch to do some local work (using git personally), I got a file that will not "reset". I see that it's different from similar files in the same directory in that it has a backslash as part of the name: icon#2xios8\.png. I suppose the backslash doesn't do anything on other platforms but msysgit on Windows 10 complains that it's unable to create the file.
I can't figure out how to make git ignore this subdirectory and let me continue with unrelated work. But I really need to fix it somehow so git can be used.
You can do this with git-read-tree and sparse checkout (git-read-tree).
Therefore you call
git config core.sparsecheckout true
Then create a file .git/info/sparse-checkout (with touch .git/info/sparse-checkout in msysgit bash). Edit this file and change its content to:
/*
!icon#2xios8\\.png
This tells git to look at all files in your working directory (/*) but '!icon#2xios8.png' (!icon#2xios8\\.png). Notice the escaped backslash here (\\)!
After you run git read-tree -mu HEAD you should be able to pull your repository by ignoring that specific file.
I`m working with Git Bash on Windows. But before, I was working with Git Shell (from github). In Git Shell was this really awesome thing, See the image below:
In Git Shell, I do not need to use git status to see how many untracked, changed or deleted file I had. Git Shell shows that information after any command.
How can I do this for Git Bash (on Windows)?
You can simply manipulate the PS1 variable, something like this might help you:
$ PS1="$PS1 [`git diff --shortstat`]> "
The result should be something like this:
rlegendi#localhost /.../gitrepo (master)
[ 1 file changed, 3 insertions(+)] >
So basically you have to add this like to your profile file (either at the Git installation directory typically under c:\Program Files (x86)\Git\etc or in your home directory). That way you can create a bit nicer version.
Take a look on PROMPT_COMMAND and different git diff switches (like --numstat, etc.).