Can't commit update-index on Windows - windows

I have a executable file called post_deploy that's run on my OpenShift gear after a push, but it wasn't executable so I ran:
git update-index --chmod=+x .openshift/action_hooks/post_deploy
But every time I did a git add to commit the file, the file would loose the executable permission. If I tried to do a commit, git would tell me there was nothing to commit. I eventually had to pop over to Cygwin to get it to work, but how can I get this to work in Window's Command Prompt?

Check your Git version: with Git 2.9.1, you can add with chmod
git add --chmod=+x -- yourFile
Also check the value of git config core.filemode. I suspect it should be false (which is expected in an environment which does not support executable bit).
Still, the add --chmod=+x should be enough to record that executable bit in the Git repo.
Finally, clone your repo in a Linux/Cygwin environment and check if the file is not already executable there.
The OP NicholasJohn16 reports below using "How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git?" to solve the issue.

Related

pre-commit hook not working in macOS but working in Ubuntu

I have a git pre-commit hook script to validate certain thing during commit.
This in my script .githooks/pre-commit
#!/bin/bash
echo "Here I am!"
This is the file permission
In ubantu when I am committing anything I am able to view the echoed message, where as when I doing the the same thing in MacOS I am getting this error
fatal: cannot run .githooks/pre-commit: No such file or directory
git config is .git/config
line break type is CRLF
Also when I am directly running the file (in MacOS) from CLI like this, it is giving me the desired output.
./.githooks/pre-commit
My git version is 2.32.0 (Apple Git-132)
could you please try this and see if it's working for you?
brew link --overwrite git
brew update git
You should have the latest version of git -> 2.35.x
Now go to your local repository, i.e. the project folder, and then to the .git/hooks directory under your project folder.
You can place your hook files here. I.e. for pre-commit, the file name should be pre-commit (without any extension).
This should work whenever you try to commit to that specific repository. The main problem in your case seems to be the directory. The hooks should be in the .git/hooks directory of the project folder.
See the screenshots below.

Why does my git bash always start at master branch?

I have a Windows PC with git installed. Whenever I start git bash, it always stand at /c/Users/_user with master branch as below:
NativeKiwi#nkiwi MINGW64 ~ (master)
I think it should look like this:
NativeKiwi#nkiwi MINGW64 ~
I had a look at people around, found out that they don't have (master) at their first start using git bash. I checked git repo at where I stand with git remote -v but there is nothing.
The string shown in your prompt depends on your PS1 environment variable.
Please check your .bash_profile or .bashrc for the configuration of PS1 environment variable.
I had the same issue (due to running git init) in the wrong directory and fixed it by running rm -rf .git in that directory.
You are seeing master because you created a git repository at the current path using the git init command. Always create git repositories in the folders containing project files. Consider running rm -rf .git command.

git checkout -- <filename> doesn't recover a locally deleted symbolic link on Windows 10

So, yes, I am using Windows 10, when everyone around me at the office is using Linux/Mac. But I won't give up.
I deleted a Symlink which is part of the repo, that was locally created by "git clone" - (Read below why if you are bored)
Now when I run "git status" it says : "Deleted" for my symlinks. I want them back, so I tried the following :
git checkout .
git checkout --
git reset --hard HEAD
Nothing worked, they all completed without errors, but "git status" still shows the symlinks are deleted, and indeed "ls" shows they are gone. Any attempt to create them myself using "ln -s" (in git-bash) results in "typechange" in git status.
How can I get "git checkout ." or any other git command to restore the symlinks to be as they are in the repository?
So, yes, the timestamp should reveal I posted the question when I already knew the answer, but, as I spent almost two hours trying to resolve this, and the answer is not on stackoverflow (yet) I decided I shell post my question anyway and answer it.
Eitam#DESKTOP-JJOOD64 MINGW64 /d/git/my-repo (master)
$ git checkout .
Eitam#DESKTOP-JJOOD64 MINGW64 /d/git/my-repo (master)
The command seems to have completed with no errors or problems, but "git status" will still show my symlinks are not there.
The solution :
run git-bash as Administrator!!! and use "git checkout ." or "git reset --hard HEAD" or any git command that was supposed to work in the first place.
It's quite annoying that git-bash didn't complain that it's missing Administrator privileges. I found out that it's needed when I tried to work around the problem by creating the symlinks myself using "mklink" which told me I need admin priv...

`git add` doesn't add files to track on Windows

I have a local folder which I wanted to convert to a Git repository and then push to a remote repository. I ran the command git init in the project folder and then used the command git add .. When I run the command git status, I get the message that I have untracked files. I ran the git add . command multiple times but I see the same message.
What should I do to track these files so I can push to a remote repo?
I'm using Windows 8.1 x64 machine.
UPDATE: Please see the answer below.
I used the command git config --system core.longpaths true to fix the error for longer file names. I was able to add all files after making that change.

git windows post pull

I have recently converted from svn.
My server is under Windows (don't blame me, it wasn't my choice :}
I have created a repo with two branches "master" and "stable".
On my server I want to get files from stable branch.
I have done:
git clone git://url/.git src
cd src
git checkout --track -b stable origin/stable
Previously I had a .bat script
cd my_repo_dir
svn update
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2
and it worked, now with git
cd my_repo_dir
git pull
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2
nothing is executing after git pull, whether it is successful, or up-to-date.
It just exits to prompt with no warning.
I thought about hooks.
I have created:
.git/hooks/post-receive
.git/hooks/post-update
both files with the same contents:
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2
and nope, it is not executing either...
Maybe I am missing interpreted declaration line (#!/bin/sh on *nix)
but I am not sure what it is on windows...
Few points:
Make sure you have git.exe on path. Do a where git and you must get something like
C:\Program Files (x86)\Git\bin\git.exe
If git.cmd is being used ( from C:\Program Files (x86)\Git\cmd\git.cmd ), you have to do call git pull for it to continue execution. I would say add git.exe to path and start using it.
Even on Windows, you must have the shebang - #!/bin/sh for the hooks to properly run.
If you want a hook to run on pull, you probably want to use the post-merge hook. post-receive and post-update run on remote repos when you push to them.
git is probably a batch wrapper around the real executable. Use call git pull.
And those hooks only fire when content is pushed from a remote location, as far as I can tell from the documentation. So they're ignored for pull.

Resources