Subtitle: Using Git with Dropbox to manage data
purpose
I usually use Git to manage all the data I need to save.
I need to use a command to commit all git repositories at work to my Ali Cloud or Dropbox and use it in different places.
Another benefit of using Git with Dropbox is that since.gitignore ignores many common resources, Dropbox needs to store very little:
As you can see, I only have a 430MB repository on Dropbox with 8.75GB of project files and Git version management.
If you have the same needs as I do, this article will help you.
Problems need to be solved
- Each Git repository retains its original Git functionality and does not need to be changed at all, as they need to keep working as usual
- Git Submodule and SubTree have some changes to the original repository, and cannot fulfill the above requirements well
- There is a unified warehouse that manages all of these warehouses
Use merge-sub-gits to solve the above problems
The installation
First, make sure you have the Nodejs environment and install merge-sub-gits
npm install -g merge-sub-gits
Copy the code
Principles and Commands
The idea is simple:
- Before git commits or pulls, hold the child Git project’s
.git
Rename the folder to.__originGit__
Folder, - When submitted or pulled, the
.__originGit__
Rename the folder back.git
Shell command
Go through the current directory subfiles and rename all.git to.__origingit__
merge-sub-gits origin -l
Go through the current directory subfiles and rename all.__origingit__ back to.git
merge-sub-gits local
Print the rename log
merge-sub-gits xxx -l
Copy the code
Submit the project
merge-sub-gits origin -l Go through the current directory subfiles and rename all.git to.__origingit__
git add .
git commit -m 'xxx'
git push
merge-sub-gits local Go through the current directory subfiles and rename all.__origingit__ back to.git
Copy the code
Adding the -l parameter will print the rename log
Pull the project
merge-sub-gits 'origin' -l
git pull
merge-sub-gits 'local'
Copy the code
Set for the above operationshell
Quick function
You can add the following to ~/.bash_profile:
# Recursively modify sub-Git projects to commit from the root Git project
function merge-sub-push(){
merge-sub-gits 'origin' -l
git add .
if [ "The $1"= ="" ];then
git commit -m "no commit message"
else
git commit -m "The $1 $2 $3 $4 A $5 $6 $7 $8 $9"
fi
git push
merge-sub-gits 'local'
}
# pull all items
function merge-sub-pull(){
merge-sub-gits 'origin'
git pull
merge-sub-gits 'local' -l
}
Copy the code
Then use the following command to submit:
# submitMerge-sub-push fixes the following bug 1.xxx 2.xxx# pull
merge-sub-pull
Copy the code
Work with Dropbox or various web disks
If you’ve already seen the above and have some basic Git experience, you don’t need to read on and you can use merge-sub-gits on your own.
Most of us need to keep our work files on a variety of web drives for easy synchronization at work and at home, but Dropbox\iCloud and other web drives don’t give folder neglect and a more nuanced Git file history.
For example, a React front-end project is probably a few hundred MB, and if you ignore the node_modules folder, you’re left with a few dozen MB.
We can put all the work and computer environment related materials into a work file and use merge-sub-gits to synchronize the contents of the changed folder to the web disk:
Start by creating one in Dropboxbackup-all.git
warehouse
Use iCloud to create a repository at: ~/Library/Mobile Documents/com~ Apple ~CloudDocs/
Use Dropbox to create a repository at: ~/Dropbox
cd ~/Dropbox
git init --bare backup-all.git
Clone local git from ~
cd ~
git clone ~/Dropbox/backup-all.git
Copy the code
Now that we have created a repository in Dropbox and cloned it locally, we will copy all the files that need to be backed up into ~/backup-all and continue:
usemerge-sub-gits
Make a backup
cd ~/backup-all
# backup
Remember to create a.gitignore file ahead of time and write what you need to ignore
merge-sub-push
# read
merge-sub-pull
Copy the code
As mentioned above, through.gitignore file and git compression, the 8.75GB content is changed into 430MB for web disk management, and there is a Git version management function.
Clean up the Dropbox
Git repositories contain a lot of historical information, which slowly grows over time. Since all of our sub-projects keep their Git history, if the root Git repository becomes too redundant, we can simply delete the Dropbox Git repository and resubmit it.
Fix masked child Git projects
If you have ever used a Git commit in a root git project, the child Git project will be marked as commit ignored. In this case, you need to clear the Git record:
Replace and empty the master branch from the current branch
git checkout --orphan latest_master
merge-sub-gits 'origin' -l
git add .
git commit -m "clear master"
git branch -D master
git branch -m master
git push -f origin master
merge-sub-gits 'local'
Copy the code
The warehouse address
Github.com/ymzuiku/mer…