When I try to add a submodule via
git submodule add git#domian:repo.git contact
I get the following message:
The following path is ignored by one of your .gitignore files:
contact
Use -f if you really want to add it.
Here is my .gitignore:
# Ignore everything
*
# But not these files:
!*.py
!*.md
!*.gitignore
!.gitmodules
!contact/
It is resolved by using the suggested -f option, but I am curious why the !contact/ entry in .gitignore does not alleviate the problem.
A submodule is composed of a gitlink (a special entry 160000 in the Git repository index), and a remote URL+path in the .gitmodules.
So excluding !contact/ would still ignore the gitlink "contact" (which is not a folder contact/, but a special "file")
This would work better, and allow the git submodule add to proceed:
!contact
And if any other cause would still block the git submodule add, the next Git 2.26 (Q1 2020) will provide a more helpful error message.
I don't hit that error in your particular case (I have git version 2.21.0.windows.1).
I do hit that error when trying to add a submodule outside the parent repository, though (which apparently isn't supported):
$ git submodule add https://github.com/user/repo ../repo
The following path is ignored by one of your .gitignore files:
../repo
Use -f if you really want to add it.
Best guess is it's a bug...so adding !contact/ to your .gitignore doesn't fix it because it's not actually the .gitignore causing the problem.
What git version do you have? You can download the source code for your particular version, search for the error message (e.g. here it is in v2.21), and trace through the code to figure out what actually goes wrong.
Related
It's been 14 years since I last worked with svn and appearently I have forgotten everything...
I have an existing web-project, consisting of a bunch of php, html, js and other files in a directory tree on a V-Server. Now I want to take these folders under version control and create a copy on my local machine using svn. So I installed subversion according to these instructions: https://www.linuxcloudvps.com/blog/how-to-install-svn-server-on-debian-9/
Using the already-present apache2.
But now I kinda hit a roadblock. If I try svnadmin create on the existing folder, it tells me that is is not empty and does nothing really. All the questions and answers I find here and elsewhere are either
a) focussing on an already existing folder on the local machine
b) assuming more prior knowledge than I have right now aka I don't understand them.
Is there a step-by-step guide for dummies anywhere on how to do this? Or can anyone tell me in laymans terms how to do this?
I can't believe this case never comes up or that it is really very complicated.
At the risk of failing to understand your exact needs, I think you can proceed as follows. I'll use this terms:
Code: it's the unversioned directory at V-Server where you currently have the bunch of php, html, js and other files
Repository: it's the first "special" directory you need to create in order to store your Subversion history and potentially share it with others. There must be one and there can only be one.
Working copy: it's the second "special" directory you need to create in order to work with your php, html, js... files once they are versioned and it'll be linked to a given path and revision of your repository. At a given time there can be zero, one or many of them.
Your code can become a working copy or not, that's up to you, but it can never become a repository:
$ svnadmin create /path/to/code
svnadmin: E200011: Repository creation failed
svnadmin: E200011: Could not create top-level directory
svnadmin: E200011: '/path/to/code' exists and is non-empty
Your repository requires an empty folder but it can be located anywhere you like, as long as you have access to it from the machine you're going to use in your daily work. Access means it's located in your PC (thus you use the file: protocol) or it's reachable through a server you've installed and configured (svn:, http: or https:).
$ svnadmin create /path/to/repo
$ 😎
Your working copies can be created wherever you need to work with your IDE. It can be an empty directory (the usual scenario) or a non-empty one. The checkout command retrieves your files from the repo and puts them in the working copy so, at a later stage, you're able to run a commit command to submit your new and changed files to the repository. As you can figure out it isn't a good idea to create a working copy in random directories because incoming files will mix with existing files. There's however a special situation when it can make sense: when the repository location is new and is still empty. In that case you can choose between two approaches:
If you want code to become a working copy, you can check out right into in and then make an initial commit to upload all files:
$ svn checkout file://path/to/repo /path/to/code
Checked out revision 0.
$ svn add /path/to/code --force
A code/index.php
$ svn commit /path/to/code -m "Import existing codebase"
$ Adding /path/to/code/index.php
$ Transmitting file data .done
$ Committing transaction...
$ Committed revision 1.
If you don't care about code once it's stored in the repository or you want your working copy elsewhere, you can import your files from code and create a working copy in a fresh directory:
$ svn import /path/to/code file://path/to/repo -m "Import existing codebase"
Adding code/index.php
Committing transaction...
Committed revision 1.
$ svn checkout file://path/to/repo fresh
A fresh/index.php
Checked out revision 1.
I need to switch from Composer (which is used by Symfony2 by default) to Git submodules.
I thought I could just add the desired submodules to the desired locations, thus overwriting the current version which was installed by Composer.
But when I use git submodule add, it says:
'vendor/twig/twig' already exists in the index
So I tried:
git rm vendor/twig/twig
and tried to add the submodule again, same error.
What am I doing wrong?
I'm founder and ceo of cloudControl. Currently composer does break our image building process because it interferes with the logic we have to detect submodules in some way. The team is aware of this problem and working to fix the underlying issue.
I'm working for cloudControl and we've been lately inquiring into this issue.
Regarding the original problem, you proposed already a right solution for replacing the composer packages by git submodules, it was just a git commands issue. But doing this doesn't make much sense, as long as these git submodules are identical to the Composer packages and your php code is still hanging on the autoload.php provided by Composer.
We don't process internally Composer yet, their files are just added into the repository and the php code requirements make the rest. However we do process git submodules, so if you want to make a real switch from Composer to Git Submodules, the best option is getting rid of Composer files (vendor folder and composer.* files), adding git submodules wherever you want and handling again the php dependencies . Thus everything should work fine and you'd have switched completely to git submodules.
Native support for Composer is in our future plans.
The problem was that i had to actually delete and git-remove the repository first.
i.e. for twig what i did in the end was:
git rm -r vendor/twig/*
rm -r vendor/twig/*
git add vendor/.
git submodule add git://github.com/fabpot/Twig.git vendor/twig/twig
git submodule add https://github.com/fabpot/Twig-extensions.git vendor/twig/extensions
Now i have twig and twig extensions as a git submodule and can use it in my cloud application.
How can I retrieve the current Git commit version from within a Ruby on Rails app?
Want to display the Git version (or maybe the last 6 letters or so) to serve as an App version.
Like #meagar said, use backticks to execute the shell command from within your app, but you may find these two commands more useful:
Full hash:
git rev-parse HEAD
First 7 characters of hash:
git rev-parse --short HEAD
You can invoke the git command from within your script:
commit = `git show --pretty=%H`
puts commit
Depending on your environment you may want to use the full path to the git binary, and possibly specify the GIT_DIR via an environment variable or --git-dir.
A more robust solution would be git show --pretty=%H -q. The -q flag quiets the output.
In order to remove the newline that is part of the output, you can use chomp. For example: system('git show --pretty=%H -q').chomp
The selected answer has the potential to actually return the diff when the commit is not a merge commit. Verified on git version 2.16.2.windows.1.
I presume that you want to include the app version in your HTML somewhere? The prerequisite is that you are deploying your repo with Capistrano in the default manner (you are uploading the repo, not sending up an archive file).
You can add some code to the Rails initializer as outlined here. That approach will get the SHA1 from the last commit, and make it available as an environment variable.
The other way to do it is have you Capistrano task generate a static file in the public directory with the commit SHA in it. You could include other info in this file that seems useful.
If I tell git to ignore x amount of files and never add them to the repository, will those files also make it into the svn:ignore property? And if so, how can I keep .gitignore local to only my local git repository?
EDIT Sorry about the duplicate, I searched on here and couldn't find anything on it.
No, git will not do anything with svn:ignore.
From the documentation:
We ignore all SVN properties except svn:executable. Any unhandled properties are logged to $GIT_DIR/svn//unhandled.log
Also this other StackOverflow question is very similar.
If you want the .gitignore local to your repo, don't commit it.
Similar question:
How can you indicate files to ignore in svn when using git and the git-svn bridge
git-svn does neither .gitignore — svn:ignore, nor git attributes — svn properties conversion.
You may consider using SubGit instead. It does properly handle ignore, properties, merge-tracking data, etc. Among other things it works on a server-side, so one can use any Git client available to send changes to Subversion repository.
See documentation and comparison with git-svn.
I'm getting a hang of git submodule (wishful thinking?) and I'm coming up with more specific questions, which is a good sign...
I've tried to find the which revision of the submodule the superproject refers to, in .gitmodules and .git/config, but nothing is mentioned there...
The scenario is that I'm changing submodules in their root locations (from which they're imported), and then pulling them in where they're "submoduled"...
Beyond committing from the superproject to incorporate those changes into the superproject repo, do I also need to do "git update" to register the new pulled in submodule commits?
Basically the question is:
do I need to "git submodule update" only when I first clone the superproject, or after every pulling of the submodule (from its own repo)?
Thank you
As mentioned in my previous answer to git submodule update, that command checks out the specific version of the project, base on their .gitmodules file.
The GitPro page does insist:
This is an important point with submodules: you record them as the exact commit they’re at.
You can see which commit is referenced by running within the "super project" (the one referencing one or several submodules):
git submodule status (except if you did some commit directly within that submodule, in that case it will show a "+" in front of the SHA-1 of the HEAD of any submodule that has advanced from the SHA-1 stored in the superproject) or
git ls-files --stage looking for entry in mode "160000", a special entry in the Git index.
That means, each time you execute a git command in the "super project" which could modify that submodule commit SHA1, you need a "git submodule update".
do I need to "git submodule update" only when I first clone the superproject, or after every pulling of the submodule (from its own repo)?
Yes, you have to do this every time you pull down a submodule change in the main project.
That is because you are referencing the exact commit the submodule original repo is at (as said above), and when you pull that repo, you are effectively modifying that commit.