Is this a bad idea or is there a better way of approaching version control for my whole dedicated server?
My first attempt was git init and git push but I couldn't resolve error:
error: src refspec main does not match any
error: failed to push some refs to 'main'
I tried several fixes and workarounds from StackOverflow.
So then I tried creating a repo from GitHub.com with just a test file, then cloning it, cd /, git add ., etc.. but I keep running into errors with it too.
fatal: destination path '.' already exists and is not an empty directory.
..is what I get after running git clone git#github.com:hero/128GB.git .
Any ideas on what I should do next? If I should continue this path or is there a better approach at version control for a server?
I recently updated the development server that hosts our code repos to a newer version of Ubuntu (18.04). As part of the process git was upgraded to version 2.23.0. The actual application servers where the code gets deployed to need to be able to checkout the latest changes from the git repos. When I try to do a 'git fetch' on those servers I get a long list of errors that look like this:
error: index file
./objects/pack/._pack-5b58f700fea57ee6f8ff29514a376b945bb1c8a9.idx is
too small
I did some digging around to see if I could come up with a solution but so far noting has worked. I tried the answers listed here: git error: "index file is too small" .
Neither git index-pack nor git repack -a -d solved the issue. I even tried deleting the local copy of the files from the application server and installing fresh using git clone. The clone itself threw a bunch of errors similar to before
remote: error: index file
./objects/pack/._pack-5b58f700fea57ee6f8ff29514a376b945bb1c8a9.idx is
too small
At this point I'm out of ideas. Any help would be appreciated.
Edit: The output of du -h suggests that there is enough disk space.
The error message sounds like file corruption. If you have not run out of disk space, you can delete the index file and recreate it with:
git index-pack -v ./objects/pack/._pack-5b58f700fea57ee6f8ff29514a376b945bb1c8a9.idx
You might also want to run use git-fsck to
verify the connectivity and validity of the objects in the GIT database -- both the remote the local one.
If your index is corrupt, you can also try to reset the branch which will create a new index file:
To be safe, backup .git/index.
Remove the index file .git/index.
Perform git reset
References
The issue is a possible duplicate of git error: "index file is too small"
Documentation on git index-pack can be found at https://git-scm.com/docs/git-index-pack
Some notes on repairing a broken index: https://makandracards.com/makandra/5899-how-to-fix-a-corrupt-git-index
fatal: packfile name 'server' does not end with '.pack'
I encounter this error when transfer my git repo from Mac OS to another system. Files start with '._' are Mac OS meta files generated by tar command. So look at this question to avoid '._*' files: Tar command in mac os x adding "hidden" files, why?
About one month about I've created bare git repository.
And over last month I've been committing my source changes from eclipse to that repository over SSH.
The problem occurred today, when I tried to commit and push updates from eclipse. Here is whole error I've got:
Repository ssh://dany#192.168.0.18:22/home/dany/git/SVP2/
missing necessary objects
error: object file ./objects/60/916b83370c1535a4be9924e71e9954c01e82e0 is empty
error: object file ./objects/60/916b83370c1535a4be9924e71e9954c01e82e0 is empty
fatal: loose object 60916b83370c1535a4be9924e71e9954c01e82e0 (stored in ./objects/60/916b83370c1535a4be9924e71e9954c01e82e0) is corrupt
error: object file ./objects/60/916b83370c1535a4be9924e71e9954c01e82e0 is empty
error: object file ./objects/60/916b83370c1535a4be9924e71e9954c01e82e0 is empty
fatal: loose object 60916b83370c1535a4be9924e71e9954c01e82e0 (stored in ./objects/60/916b83370c1535a4be9924e71e9954c01e82e0) is corrupt
I can assume what is wrong, but I dont know how to solve it.
I think it may be related to the error on linux server where that repository is:
Read-only file system
I don't know why and when my system switched to read only mode.
I'have back ups:
source code in my local machine in eclipse project, wich is also local git repository
git bundle file of this git repository
Can they be use to restore repository to working one?
Please help. I am frightened.
I am quite new to git. I don't have any team member to ask for this. Please help.
-------------- Edit ---------------------
Thanks to: #codeWizard
On Remote bare repository
dany#192.168.0.18:~/git/SVP2$ git fsck --full
error: object file ./objects/06/b08928836077489d0ede51a0af42c7807b1943 is empty
error: object file ./objects/06/b08928836077489d0ede51a0af42c7807b1943 is empty
fatal: loose object 06b08928836077489d0ede51a0af42c7807b1943 (stored in ./objects/06/b08928836077489d0ede51a0af42c7807b1943) is corrupt
korbeldaniel#192.168.0.18:~/git/SVP2$
On Local working repository
dany#dany1l:~/git/SVP2$ git fsck --full
Checking object directories: 100% (256/256), done.
dany#dany1l:~/git/SVP2$
As you can see its all about the same object.
Verify that the repository is in a "good" state:
git fsck --full
It will verify that all the files in your repository are in a "good" state.
In case of errors to any of the files it will display that a given hash is not good which means that if the file is in the list and its not a dangling state the checksum (SHA1) does not match the content.
It this case the file is corrupted.
If the file not corrupted
If you want to verify that the problem is not in your current branch, checkout last working master, create new branch form it and try to push the new branch.
If the push is working so you have verified that the problem is in one of your repository files.
I had normal dir and file backup of git repository in zip archive, which I used to restore, fix error.
~/git rename to ~/git_old_corrupted
unzip git folders and files structured backup into ~/git
commit and push to remote repository (one which was earlier corrupted)
This commit have pushed my all earlier commits at once.
Now it is back to normal again.
I have cloned a GitHub repository into a new directory on my local machine using:
git clone git#github.com:*****/project.git destination-dir
Clone worked fine but whenever I try to pull or push I git this error back:
error: insufficient permission for adding an object to repository database .git/objects
fatal: git write-tree failed to write a tree
What have I done wrong? And how can I fix this. From what I read so far online, the problem is trivial if you are using your own repository (i.e. not GitHub) but what should I do if this on GitHub (there is no ssh access).
Also, I should add that I have another directory on my machine pointing to same repository on GitHub which is fine for pulls and push.
This doesn't look like related to GitHub per-se.
From what you say in the comments, it seems that the write permissions inside the hidden .git folder (which contains all of your local git repository data) were not corresponding to the permissions that your git client had when you ran it.
It can be that you cloned the repository with one user account (or using sudo), but where trying to pull/push from a different user. If that wasn't the case, something could have messed your local files permissions while cloning.
As you stated, doing chown -R login:group projectDir/ fixed the problem because it recursively reset all permissions in your project folder (including those of the .git folder and its contents).
A good experiment would be trying to clone the same repo to a different folder to see if the problem reoccurs. If it does, maybe something is wrong with your default permission usermask and/or your git client permissions.
I'm just entering into the wonderful world of git.
I have to submit a bunch of changes that I've made on my program, located in a directory called /var/www/myapp.
I created a new directory /home/mylogin/gitclone. From this directory, I did a git clone against the public repo and I was able to get the latest copy created.
I'm now trying to figure out how to take all the files in my working folder (/var/www/myapp) and "check them in" to the master repository.
From /home/mylogin/gitclone, I tried git add /var/www/myapp but I'm getting an error that the folder I tried to add is outside the repository.
Can you give me a few pointers on what I'm doing wrong? Also, I'd like to add everything, whether it's different from the master or not.
Thanks.
First in the clone folder you can create a Branch (so the master stay untouched)
git branch [branch_name]
After, just copy the files you want from your old folder to the clone folder.
When you are done, just add / commit your change and Merge your branch into the "master" branch. It will look like to something like this:
git add .
git commit -m "Comments"
git checkout master
git merge [new_branch]
Try this tutorial from GitHub.
You'll have to move all the files from /var/www/myapp to /home/mylogin/gitclone and then do a git add . and then git commit -m "Your message".
When upgraded to git version 2.12.2 that error appeared, I nooted the i add the file with a full path like:
git add c:\develop\project\file.text
when removed the full path it start working, like:
git add file.text
To add some files or folder to your repository, they have to be in the folder you created with git clone. So copy/paste your application in your local git folder and then go in it and do git add * and then you'll be able to commit to the server with git commit -m 'message' and finally push the changes to the server with git push
Okay, this error came up for me because I moved the project from one computer to another.
So the git was not able to figure my global git user.name and user.email
I opened the command prompt and specified my old git user.name and user.email from previous computer. Kindly run the following commands and it should be fixed.
cd pathToMyProjectDirectory
git config user.name "myName"
git config user.email "myEmail"
That's because you are versioning stuff inside /home/mylogin/gitclone and git tracks everything inside that folder. You cannot track other folders outside of this repository.
A solution might be create a submodule, or using a symbolic link using ln -s
Git only tracks files and folders within the root folder which includes the .git directory and the subfolders inside root folder. The folder you are trying to add is outside the scope of git.
What would you actually like to do is first git checkout -b myapp which will create and checkout a new branch based on the master branch of the repository you cloned. Then you would actually copy all your files over and commit them with git commit -a -m "Short descriptive name about what you did". The parameter -a you passed to git commit is for including all the changes done to the repository and -m is to include the commit message in the actual command. After that you can either push back to the main repository if you have write access to it or push it to your own public repo or don't push it at all.
What I've described above is pretty much the basics of git. Try reading this book which is pretty descriptive.
Maybe someone comes along having the same trouble like I had:
In my case this error was thrown while using husky (commit hooks) https://github.com/typicode/husky
It was just an error because of encodings. My source was located in a directory that contains a special character ("รถ")
Seems like husky uses "git add" with the absolute path of the source which fails somehow at this point
I renamed the path and it worked fine.
This message can also appear when the file name is listed in the .gitignore file.
My scenario is that the git repository's path has symbolic link and git throw out this error when add file say to "/home/abc/GIT_REPO/my_dir/my_file".
and "/home" is actually a softlink to "/devhome".
code ninja gave me some light when I tried to debug this case.
So I tried get the target directory by using the command readlink -f /home/abc/GIT_REPO before run add command.
And then everything works like a charm !
I encountered the issue at Windows box with maven-release-plugin.
The plugin tries to add files using absolute path and I have noticed that the path in the Git add command starts with uppercase D: while the path in Working directory: log line started with lowercase d:
I have added core.ignorecase = true to the Git settings and the issue was gone.