Is there a chance to recover the .git/config file? - windows

The .git/config file has mysteriously disappeared from my working repo.
I have lost my remotes and the smudge/clean filters.
Is there a chance to recover the .git/config file?
I'm using Windows 7.

It has nothing to do with git, git does not have a cache mechanism for any of its content.
You will need to use 3rd party recovery tools.
Try Piriform's Recuva

git clone your remote repository (you could interrupt the process just after the file is created), or do a git init in an empty directory and copy the file in your working repository. It should be a good start.
Perhaps you will have to add some remotes or some other info but nothing very important...

Related

Issues getting Git working with VSCode and files on web host

Until now I have always used FileZilla for transferring my local files to my host for changing a site Im working on. I want to change that and learn how to git gud! So basically the ideal situation would be to be able to work in VSCode on a directory which is mirrored from my web host and from there be able to make changes locally and then commit and change files on my web host when I want to - this has to be possible right?
I have been able to use Git Bash to connect to my host and files using ssh. I have created both an init --bare and init since Im not sure which one to use, but I do have the .git folder created there. I can also using the Bash and the command git status see all the files waiting for to be committed (?).
As I understand I have to initialize the repository, then commit them to "track" these files and have them visible in VSCode to work with, is this right?
But when I try to git commit following error message is displayed.
Waiting for your editor to close the file... code --wait: code: command not found.
This points to that the relative pathing to vscode and/or git is not working, but it is. When I start-up the bash I can use for example code --help and git config --global -e to launch a window of VSCode. So my git config --global core.editor "code --wait" is probably working as it should.
Although AFTER I have connected to my web host using ssh, neither of these command work anymore. Why is this?
And also, am Im on the right way right now in thinking on how to make this "connection" between VSCode, git and my web host (one.com)?
Im thinking that I have to create a local repository in the folder where I today have a duplicate of my web host-files and a remote repository at the actual web host and then make some kind of connection between them two and VSCode. Im not quite sure how yet.
Thanks in advance
I think you might be a little confused with what Git is and how you should be using it for what you want to do. Let's clear some stuff up.
Simply put, Git is a version control system for tracking changes to files over time. You create or edit your files, git add them to a "staging area" and then git commit them with a commit message. If you edit the files after committing them, then git can detect changes to the files and you can add and commit them again, or discard them depending on what you want. However the most important part to understand is that these changes are local at this point. If you want to share them with anyone (or have another system pull them down), then you will need to establish a remote repository.
This is what Github/GitLab are for. Log in/create an account on either site (gitLab provides free private repos) and create a repository named appropriately. Then once you have created a remote repo, follow the instructions to add it as a "remote" to your local repo, then git push your changes up to that remote one. Now, on your server, you will git clone the remote repo and that will pull down your changes. From then on, if you push new changes to the remote repo, you can pull the changes down to the server by doing git pull. This is a very basic and barebones approach to deploying code on the server and there are more sophisticated ways of doing it but I will keep it simple in this answer.
Git is completely separate from VSCode (although VSCode has some git integration and plugins). I would not recommend changing the core.editor to VSCode. What that setting controls is the editor that is used to author commit messages. Loading up VSCode takes too long for that...I recommend that you stick with the default Vim or use nano. Or, in most cases, specify a message when committing: git commit -m "added foobar".
So, the git repo that is on your server (the one that you init'd with --bare) is junk and should be instead created by git cloneing from a remote repo. Hopefully this makes sense!

Is it possible to fix Windows altered case of file names with pull from remote git repo?

I have a problem where a Windows file restore changed the case of some file names. This causes a trainwreck with some projects.
Fortunately these projects are pushed to remote git servers. The remotes are up to date with origin/master, and cloning the projects is a solution. The only problem with that is the time-consuming task of replacing git-ignored files and dealing with other updates.
An ideal solution would be to pull down all files from the remote, overwriting the files in the origin/master. Is this possible? How do I force a pull down or merge, even though they are already a match. I want to keep it that way, just use git to rewrite the correct file name cases.
git pull or git pull -f results in Already up-to-date.
First, set git to be case sensitive. By default this was set true to match Windows:
git config core.ignorecase false
Check the list of changed-case file names Windows messed up. At the very least, this is your list of files to fix:
git status
Now, delete the files and folders that are messed up. Do not delete git ignored files! Files in .gitignore must be fixed the hard way.
Now, get your deleted files back as they were before Windows changed the case:
git checkout .
Yet another reason to quit Windows.

Tower (Git client) not cloning all directories to the local machine from the remote repository

I have an issue with a new remote repository that when cloned using Tower, doesn't clone all the directories.
When I created the remote repository, I did the following:
Created a .gitignore file containing the following line
files/cache/*
Then ran:
git init
git add .
git commit
I then cloned the remote repository to my local machine using a Mac OSX git client called Tower but noticed that many of the directories did not clone.
When I go back and look at my terminal session on the webserver, I can see the directories that weren't cloned listed after the initial commit - I see a whole bunch of lines that look like this:
create mode 10644 directory-name/path/to/file.php
create mode 10644 directory-name/path/file.php
create mode 10644 directory-name/path/to/file.php
create mode 10644 directory-name/path/file.php
So I'm guessing they were added but I'm also wondering if my .gitignore file is not setup right and is conflicting with Tower somehow?
I tried the .gitignore file a couple of ways, firstly like this:
files/cache/*
then like this:
files/cache/
After changing it to the second one, I ran git add -A (which didn't seem to add anything new) on the server and pulled the repo down using Tower again - but no luck.
Not sure if this is Git or Tower or both - not sure what I'm doing wrong, sorry.
Any help would be much appreciated.
Cheers
Ben
Don't forget that git won't add (and clone) empty directories.
(or directories with ignored content, making them empty for Git)
See:
"Does git ignore empty folders?"
"How do I add an empty directory to a git repository?"

How to change the path where Git creates ssh file while "remote add origin ..."?

Good times!
Please, hint me this moment - I use the Windows account with cyrillic account-name. When I try to add my local git repository to github.com, I get the mistake "Could not create directory c/Users/\204\206" ... and I suspect due to my account is cyrillic.
So - how to change this behavior? I want to use Git without changing or renaming account?
Git doesn't create any directories when you add a remote repository. That is, if you type a command like this:
git remote add origin git#github.com:you/yourproject.git
The only thing that happens is that git adds a couple of lines to the .git/config file.

Git on live Windows Server - Trying to pull from the repo but local files already modified

I have my Git repository hosted at github.com. I would like to push updates and such to github.com and then log into my Windows server and do a git pull to get my changes (that are verified to work on my local machine. Ideally I should have another server setup as my local machine settings are different from the live server. But I'm cheap.).
It seems like whenever I try to do a git pull on the server, the files seem to get modified somehow since the last pull. And so I am unable to get the update as git says I need to commit my local (Windows server) changes.
How can I use git like I want to? Or is there a better way?
Is it possible you change the git core.autocrlf flag after cloning the repository?
Issue 83 on the google code project form msysGit goes deeper in on this topic.
If that it the case, doing a new clone should fix the problem (as long as the flag is not touched).
Are you using the Git GUI or Git Bash?
For some reason, Git GUI on Windows does not have core.autocrlf configured by default when cloning a repo, even after attempting to set core.autocrlf in the global configuration using Git Bash (might be GUI setting or environment issue that if corrected, could make the GUI a viable option).
Also, for some reason Git GUI in some cases seems to think it's better to make a master branch in the new repo rather than using the existing branches in the repo being cloned. After Git GUI makes this master branch, it then does a checkout of this master branch immediately after the clone. Since you're using a pull and having issues, this might only have been the issue if you initially cloned using Git GUI.
Most likely, it you're core.autocrlf setting. The following steps should set up a repo for you and ensure the proper crlf settings...
Steps to Clone without Modified File Garbage:
Using the following command in Git Bash from the Windows folder clones the repo as a full copy without making an initial checkout of a branch.
git clone –n --no-hardlinks
By not checking out the branch when cloning, you now have the ability to verify your .git/config file has the correct settings for autocrlf before checking out the branch. You might want to add safecrlf just to be safe ;) To update these settings crlf settings, execute the following commands from your newly cloned Windows repo using Git Bash:
git config core.autocrlf true
git config core.safecrlf warn
To verify the changes made it correctly, open your .git/config file and you should see:
autocrlf = true
safecrlf = warn
PLEASE NOTE: You want autocrlf set to input in your Linux repo... setting to true is for your Windows repo. Also, I only use warn on safecrlf, you may want to use true.
Once you have your crlf configuration set, you can finally checkout the branch normally using git checkout .
If there are still modified files in your new local Windows clone, it's likely due to having CRLF instead of LF in your Linux repo. This can be verified by using a hex editor on the files in your Linux repo and searching to see if 0D0A is present, or if everything is just 0A as it should be.

Resources