i have some files and folder in my git repo. But some of them have a very long path that when i try to synchronize my workspace with git it gives me an error because windows cannot have characters in a path more than 260. Is there a way to pull specific files and folders? for example *.php files from /file/*.php?
I do not know much from git and also all other tutorials and answers i found here do not work. i even tried the git git_core.longpathenabled true but nothing happened.
Any ideas?
Is there a way to pull specific files and folders
Yes, you can use git filter-branch and or git subtree split
Sample code:
filter-branch
# Filter the master branch to your directory and remove empty commits
git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch
This will checkout all your desired files from the given folder to the current directory
subtree split
git subtree split -P <name-of-folder> -b <name-of-new-branch>
If your repository is hosted on Github or similar, you can download the file individually over HTTP, but you obviously will not be able to push changes.
Finally, if your copy of the repo is located in a deeply-nested folder you could move it somewhere like Users\You\Projects\cloned.
Related
A large existing PHP project that is having Unit Tests retrofitted to it. I want to have a "tests" directory in the code on the development branch which contains these unit tests and perhaps the DB fixtures also. Naturally I don't want anything in there making its way onto the production environment so I want a way of automatically excluding this directory when it's deployed. Or ideally, a way to avoid anything in there that is committed from being merged into master in the first place.
How do I manage this? There will be frequent and unpredictable commits to the test directory so I can't simply skip certain commits manually.
EDIT: I've now got four answers telling me about .gitignore. I don't believe .gitignore is appropriate here because I want to exclude something that IS to be committed but only from a specific branch.
it's called .gitignore
From the docs:
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected
source: https://git-scm.com/docs/gitignore
For examples sake, let's say you have this working tree:
|-app
|-test
|-index.php
to exclude test/ the test directory add a .gitignore on the same level as the .git folder and in it just add:
test/
commit the git ignore and make a change/add a file to test/ and you'll notice it doesn't appear when you run
$ git status
You can use .gitignore. This is a file in your project root and you can list all files and directories you don't want to commit/push. They are separated by a new line.
I've found that the way to keep a part of a branch from being merged into another branch on a permanent basis is to use sub-modules.
I created my unit tests folder as its own repository and then included it in my mainline branch (which is not the production/master branch) as a sub-module.
https://git-scm.com/book/en/v2/Git-Tools-Submodules
By default when you clone a repository, sub-modules are not cloned with it. The sub-module directory is created but remains empty, unless you also execute
git submodule init
git submodule update
Therefore it's as simple as not including the above commands in your production git clone but including them when you clone the repository for testing or development. You can make any changes to the tests directory along with the codebase and commit both together. This means tests can be developed alongside the code base without risking them being deployed to production.
I found the following aliases useful to set up to streamline git operations:
$ git config alias.sdiff '!'"git diff && git submodule foreach 'git diff'"
$ git config alias.spush 'push --recurse-submodules=on-demand'
$ git config alias.supdate 'submodule update --remote --merge'
This seems to be the correct approach to solving the problem of wanting separation of code in a single repository to be different on a per-branch basis.
What I want to accomplish:
I have juts installed git on my development server.
I create a branch out of my 'develop' branch, work on my new feature branch, commit, and when I'm done - I merge the new feature branch with the 'develop' branch.
To apply the changes for the 'develop' branch on my development server I have to log in to my server and use git pull - which I'm trying to prevent and happen automatically - when there is something to pull from my development server - it will be done automatically.
I hope I'm clear about that I'm trying to accomplish ;)
What I have done up till now is:
Created a folder inside my project /www/hooks/ and added a file called post-merge: Following git documentation - this should get triggered whenever I merge a branch.
Inside this folder I added the text:
which should execute whatever is in between the backticks symbol ( ` ) as a shell command (following this PHP documentation)
Inside the folder /www/.git/hooks/ I added a symbolic-link to the file I previously mentioned with the same exact name: /www/hooks/post-merge :
sudo ln -s -f /www/hooks/post-merge /www/.git/hooks/post-merge
I gave the linked file under /www/.git/hooks/post-merge 775 file permission as the other files.
Some notes:
My repo is on Bitbucket
My directory /www/homepage/ is the one with the index file, so nothing can run outside of it on a browser (apache2 points to it..) - (but i guess there shouldn't be a problem since it's self executed via /.git/hooks ?)
I tried renaming both my files (the one under /www/.git/hooks/ & /www/hooks/) to post-merge.php and this didn't work.
just to have Carriage return
#!/bin/bash
git --git-dir "path/master/.git" --work-tree "path/master" pull origin master
you could try this in your post-merge
By accident i deleted PHP files with:
git clean -xfd
There is any good files recover tool for Windown PC to recover those files?
Or any other good solution?
Thanks!
wish its not late for this... but... if you didn't change the remote branch yet, you can make this:
git fetch --all // make you localrepo match with remoteRepo
(you can use -- if you want to fetch just 1 branch)
git reset --hard origin/<remote_branch>
With those commands you will have your local branch as the remote branch.
Example:
File = index.html
Remote branch(dev) = <html>... a lot of stuff ... </html>
Local Branch(dev) = <html><html><html><html>Bugged or deleted<html><html>
After git fetch --dev && git reset --hard origin/dev you local branch will be like the remote one.
I want to move a git repository to a sub-directory which is there in its present root folder.
Let me explain the things first.
I have Git repository testing in $HOME/repos/ (contains PHP code-base).
Now i want to move testing into $HOME/repos/php/ where php will be sub-directory which i want to create (anyway php directory is not a git repository)
My questions are
if i do above explained move then does this effect my testing repository ?
Does this effect any branches or commits or uncommitted changes in testing repository ?
Moving a repository to a different directory should have no effect on the repository. Simply move everything as you would with any other kind of files, taking care to move the .git directory along with it. That .git directory is what git looks at and compares against other stuff in the project directory (wherever that .git directory lives).
If you are working in PHP (or I guess any programming language) and using subversion as your source control, is there a way to take your project (for example):
C:\Projects\test\.svn
C:\Projects\test\docs\
C:\Projects\test\faq.php
C:\Projects\test\guestbook.php
C:\Projects\test\index.php
C:\Projects\test\test.php
and build/copy/whatever it so it weeds out certain files and becomes:
C:\Projects\test\faq.php
C:\Projects\test\guestbook.php
C:\Projects\test\index.php
automatically? I'm getting tired of making a branch, and then going through the branch and deleting all of the ".svn" folders, the docs directory, and my prototyping files.
I know I could probably use a .bat file to only copy the specific files I want, but I was hoping there was some way with subversion to sort of pseudo ignore a file, to where it will still version it, but where you could make a snapshot of the project that ignores the files you told it to pseudo ignore.
I know I read online somewhere about some functionality that at least lets you copy without the .svn folders, but I can't find it now.
If you use TortoiseSVN, you can use the export feature to automatically strip out all of the .svn files. I think other svn things have the same feature.
Right click the root project folder, then select TortoiseSVN > Export, and tell it where you want the .svn free directory.
Copy all the files manually or using your existing method for the first time. Then, since I take it you're on a Windows platform, install SyncToy and configure it in the subscribe method, which would effectively one-way copy only the changes made since the last pseudo-commit to production for files already in production. If you want to add a file you can just copy it manually and resume the SyncToy operation.
Ok, so my final solution is this:
Use the export command to export to a folder called "export" in the same directory as a file called "deploy.bat", then I run the deploy script (v1 stands for version 1, which is what version I am currently on in this project) This script utilizes 7-Zip, which I have placed on my system path so I can use it as a command line utility:
rem replace the v1 directory with the export directory
rd /s /q v1
move /y export\newIMS v1
rd /s /q export
rem remove the prepDocs directory from the project
rd /s /q v1\prepDocs
rem remove the scripts directory from the project
rd /s /q v1\scripts
rem remove individual files from project
del v1\.project
rem del v1\inc\testLoad.html
rem del v1\inc\testInc.js
SET /P version=Please enter version number:
rem zip the file up with 7-Zip and name it after whatever version number the user typed in.
7z a -r v%version%.zip v1
rem copy everything to the shared space ready for deployment
xcopy v%version%.zip /s /q /y /i "Z:\IT\IT Security\IT Projects\IMS\v%version%.zip"
xcopy v1 /s /q /y /i "Z:\IT\IT Security\IT Projects\IMS\currentVersion"
rem keep the window open until user presses any key
PAUSE
I didn't have time to check out the SyncToy solution, so don't take this as me rejecting that method. I just knew how to do this, and didn't have time to check that one out (under a time crunch right now).
Sources:
http://commandwindows.com/command2.htm
http://www.ss64.com/nt/