I want to clone the last committed files via Git. I tried the --depth 1 parameter. But the all project was cloned. I want to download only the last edited files because the project size is too high.
The command I tried;
git clone --depth 1 https://USERNAME:PASSWORD#HOST/PATH
I want to clone last edited and updated files. I don't want to go back to the previous committed files. I will analyze the last edited files with SonarQube. I don't want to clone the all project for this. And : I'm using exec with PHP to run commands.
How can I clone only the last edited files? Thank you.
You can't just download a couple of files from a remote git repository. In order for git to restore a file, it must have all the data of the repository available. So unfortunately you will have to download the whole repository. If you would like to see which files have been changed, you can then run git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD to receive a list of modified files.
$ git archive --format=tar --remote=<repository URL> HEAD | tar xf -
Also, if your browse remote repository using some web interface like Gitweb or GitHub, then it may have 'snapshot' feature with it and you can also download the newest version.
Related
I am new to git repository. I have a 2gb limit in bitbucket and bymistake I added one images folder of 1.5 gb and pushed the code.
Now the bitbucket size is 1.8gb. To remove the folder from history I followed these steps.
Remove folder and its contents from git/GitHub's history
git filter-branch --tree-filter 'rm -rf import/images' --prune-empty HEAD
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git
update-ref -d
echo import/images/ >> .gitignore
git add .gitignore
git commit -m 'Removing images from git history'
git gc
git push origin master --force
I followed these steps and checked in my previous commits and the folder is removed. but git count-objects -v still gives the size-pack of 1.8gb
Also in the bitbucket repository settings its still showing 1.8gb
Am I missing something?
You have to go to bitbucket page in order to delete a file/files.
Go inside your repo,
select source (left panel)
pick your branch
find your folder
go inside and delete all the images you have there (there is the delete option top right where there are 3 clickable dots)
You can't delete the folder like that (for some reason bitbucket allows only file delete and branch delete manually) but you can always empty the folder manually and remove it through console in the next git push.
Caution. This work like a "hard delete" so be extra careful when you use it, and don't use it if you can use git commands.
Edit
git gc --prune=now //accepts date
Have a look at this link there are quite a few options that may suit your problem.
Another approach is the git filter-branch --force. More about this command you can find here. This command is specifically for "rewriting" git history so it will do your job. It's tricky but it will do.
One last and final approach (never used this one to be honest) is 3rd party software (Really secure as even atlassian includes it in their documentation) but is in java so first you will need to install java in order to run a java command in your console. I saw your php tag so i just leave this as last just to concider it. I leave ths link here.
My GIT repository is located /var/repo/myRepo.git. I set a GIT hook post-receive* to copy the files from my repository to the folder of my project
git --work-tree=/var/www/laravel --git-dir=/var/repo/myRepo.git checkout -f
Each time I commit and push something on the server, the file var/www/laravel/config/services.php is replaced and the modification I did on the server is replaced by my local copy.
For instance, if I manually modify the following file like this on the server (by ssh session)
var/www/laravel/config/services.php
This is the modified content of this file
It will be like that after a commit and push
var/www/laravel/config/services.php
This is the default content of this file
I tried to add /config/services.php to my .gitignore but it does not seem to work.
.gitignore
/node_modules
/public/storage
/public/hot
/storage/*.key
/vendor
/.idea
Homestead.json
Homestead.yaml
.env
/config/services.php
What should I do so this file is not replaced each time I commit something on my server ?
What should I do so this file is not replaced each time I commit something on my server?
You have only two options:
don't check it in, or
don't check it out.
Your git checkout -f command means "get me the latest commit, overwriting everything." If the latest commit has a new version of a file, that overwrites the old version of the file.
(Moreover, a .gitignore file does not mean what you think it means. It's not a list of files to ignore. It's a list of files—or name patterns—not to complain about. Usually most important, it lets you declare to Git: "Yes, I know these are in my work-tree and not in my index; don't tell me that." That's on the input side—i.e., the "don't check it in" part.)
This leads to a general rule about configurable software, where the software itself is maintained in Git, or indeed any version control system: Do not put the configuration into the version control system. The configuration is not part of the software.
Consider Git itself, for instance. You must configure Git to tell it your user.name and user.email in order to make commits with your user-name and email address. Now imagine Git came with its configuration file built into the software, that said your user name is Fred and your email is fred#fred.fred. Every time you updated Git to a new version, it would change your name back to "Fred <fred#fred.fred>". That's not very friendly, is it?
Git stores your configuration outside of the Git software. There are, to be sure, default configuration entries, but anything you set, is kept elsewhere. Updating Git does not touch this. This is not specific to Git, or even version-control systems: any system that provides upgrades must not store its configuration in a file that is destroyed by the upgrade.
So, stop doing that.
I did git rm /config/services.php and reimported the file manually. Now the file is not replaced by GIT.
I am having a really strange problem. I'll try keep it simple.
I am developing a web app using Laravel and it involves allowing users to upload and download files. I have created a function that allows a user to upload a file. This works grand. I can login to my site from another computer and see that the file was uploaded, and I can download it. So it seems to be working grand.
However, the file that I have uploaded is not appearing in the folder which it is supposed to on GitHub. This is really strange because the file definitely is there...because I can download it from another computer.
Code for uploading the file.
$destinationPath = public_path().'/files/';
$file->move($destinationPath, $file->getClientOriginalName());
I cannot see why the file I have uploaded isn't appearing on Git seeing as it has definitely uploaded.
Any ideas?
The files that you are looking for are located on your server. Adding or removing files from the server does not add or remove them from your git repository. In order to add them to your git repository, you would need to run the git commands to do so. The commands depend on what exactly you want to add, but as a general example:
To add all files
git add -A
Followed with a commit
git commit -m "example commit"
They will not appear on GitHub until you push
git push origin branch-name
For Git you have to manually commit the files.
Go to your command line and run
git status
If it shows public/ files then you would need to manually add them.
git add public
If they're not showing there, they're either being ignored or they've been committed and possibly not pushed.
First thing inside your project folder if the .git folder is created, delete it. Then write this series of code
commands:
git config --global user.name "your name"
git config --global user.email "your email"
git init
git add .
git commit -m "Initial commit"
git status
git remote add origin # paste here ssh link from github repository
git push origin master
Have a look at your .gitignore file. It might be the case that you instruct Git there to ignore the file.
I have a laravel app on Cloudway DigitalOcean, my app in /public_html , I want to update my app using git , so I have created folder private_html/git , where I pull my edited project from bitbucket, now I want to checkout it to my public_html/ , how do I do that ? Thank You
You can either deploy the changes to public/html via git or manually copy the files across.
Manually copy option
Depending on full path, something like:
cp -a private_html/git/. public_html/
Note: -a is a recursive option that preserves file attributes
This won't remove any files that have been removed in private_html/git so you would have to do that manually, or remove everything before copying the files across.
Git pull option
First, make sure you have pushed all the changes made in private_html/git to your remote (bitbucket repo).
Set up the current copy in public_html/ as a git repo.
In public_html/
git init
Then add the bit bucket remote
git remote add origin git#bitbucket.org:user-name/repo-name
Note: Get the proper bitbucket remote from your bitbucket account
Then pull the changes from the remote
git fetch --all
git reset --hard origin/master
Warning: You'll lose any differences that are currently in public/html so be careful. Always a good idea to back up everything before these kinds of changes so I'd suggesting archiving the code in public_html before overwriting it.
I was working in local git folder and committing with bitbucket. Accidently the local copy was deleted. But I had the latest local copy without .git folder. So cannot commit now. The solution I know is deleting the local copy and clone again from bitbucket. But I want a better solution for this. What is the best solution using git commands for this problem. Thanks.
I have tried to migrate code to git from clearcase.And I think my solution will match your issue.
Just keep your local copy and clone a new one which you want to push to.
And then solution is here: copy the .git folder to your local copy folder. Try git status you'll find it works and then just commit what you want.
Good luck!
Perhaps this will meet your issue.
firstly enter your local copy dir,and execute below:
> git init
> git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url <YourUrl>
> git config branch.<branchname>.remote origin
> git config branch.<branchname>.merge refs/heads/<branchname>
> git pull
> git add .;git commit -am "****" #Here commit your change, may you'll meet conflict issue.
> git push