preface

Git and SVN are both version management systems, but the differences between their commands will be followed by a simple comparison. Let’s start from the perspective of principle

4. Git and SVN commands

Let’s review the command first

role git svn
Repository initialization git init svn create
clone git clone SVN Co (Checkout)
add Git add (.remove.gitignore, * all files) svn add
commit git commit svn commit
pull git pull svn update
push git push
Check working status git status svn status
Create a branch Git branch < > SVN cp < branch name >
Delete the branch Git branch -d < > SVN rm < branch name >
Branch merge Git merge < branch name > SVN merge < branch name >
Workspace difference Git differ (-cached/head) svn diff
Update to the historical version git checkout <commit> svn update -r <rev>
Switch the tag git checkout <tag> svn switch <tag>
Switch branch git checkout branch svn switch branch
Restore files git checkout – path svn revert path
Delete the file git rm path svn rm path
Move files git mv path git mv path
Clear untracked files git clean svn status sed -e

1. Storage difference

Why do you think we use Git for code management and prototypes and high fidelity for code management and SVN?

1. Git is distributed, with local and remote repositories, and SVN is centralized, with only one remote repository. 2. Git contents are stored as metadata, all control files are in. Git, SVN are treated as files, all resource control files are in. SVN; 3. A branch of SVN is a directory; git is not. 4. Git does not have a global version number. SVN does; 5. Git content is stored using SHA-1 hash algorithm to ensure code integrity; 6. Git has a workspace, staging area, and a remote repository. Git adds code to staging area, commits code to local repository, and pushes code to remote repository. SVN is add to staging, COMMIT is commit to remote repository.

So it’s clear that since both the prototype and the hi-fi are based on a single file, it works well with SVN, while we code in lines, which works well with Git

2. The difference between.svn and.git files

1.. SVN directory

Open any.svn directory to see the structure: If you can’t view.svn, Window Computer – Go to View – Check Hide Files; Mac direct Shift + Command +.

-Exercises - Exercises - Entries - Format text file, with an integer in it, Current Version No. WC.DB Binary - Bass Exercises - WC.DB-Journal Binary

2.. Git directory structure

If you are unfamiliar with these directory structures, press Enter Git Help GitRepository -layout at the terminal and you will find that the browser will open an HTML file, which will actually open an HTML file under the installation of Git

│ ├─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag Fsmonitor -watchman.sample │ ├─ Pre-ApplyPatch. Sample │ ├─ Pre-Commit. Sample Commit will trigger this hook │ ├─ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample │ Pre-Reception.Sample INFO │ ├── Exclude - Object git data objects, including commit, trees, binary objects, ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ─ Git add - - pack-refs - - - - - - - - - - - -

So you can see that Git is more powerful than SVN when it comes to handling code

3.. Git file dynamic analysis

3.1 add stage

1. Executing git init will generate an initialized.git file, but you will find that some of the above files are not generated, because some of the files are generated with the specified command

2. Create a new test.txt, write something random, and perform git status

On branch master // No Commits Yet Untracked Files: // Uncompleted files (use "git add <file>...") to include in what will be committed) test.txt nothing added to commit but untracked files present (use "git add" to track)

Run find.-type f

./config
./HEAD
./info/exclude
./description
./hooks/commit-msg.sample
./hooks/pre-rebase.sample
./hooks/pre-commit.sample
./hooks/applypatch-msg.sample
./hooks/fsmonitor-watchman.sample
./hooks/pre-receive.sample
./hooks/prepare-commit-msg.sample
./hooks/post-update.sample
./hooks/pre-applypatch.sample
./hooks/pre-push.sample
./hooks/update.sample
./index

3. Execute git add text

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   test.txt

Run find.-type f

. / config. / objects / # 61 / de0edff4ebeeff225da34006cbe6427638fadc than before more than a document. / HEAD/info/exclude. / description ./hooks/commit-msg.sample ./hooks/pre-rebase.sample ./hooks/pre-commit.sample ./hooks/applypatch-msg.sample ./hooks/fsmonitor-watchman.sample ./hooks/pre-receive.sample ./hooks/prepare-commit-msg.sample ./hooks/post-update.sample ./hooks/pre-applypatch.sample ./hooks/pre-push.sample ./hooks/update.sample ./index

“Test. Txt” is marked “passively” after git add. “61/de0edff” is added to “object”, which means that “object” can be used to store the contents of a git repository.

5. We can check the source of the file

Git cat-file-p 61de0edf print test

Our common file systems (NTFS, FAT, FAT32) retrieve files based on address, that is, first give the specific address, and then read the file contents from the storage unit corresponding to the address number, while Git is based on content retrieval, is to search the whole content, to get a real storage location. It’s like a hash map.

3.2 the commit phase

Git commit -m ‘add test’

1 file changed, 1 insertion(+)
create mode 100644 test.txt

2.运行 find . -type f

./test.txt
./.git/config
./.git/objects/61/de0edff4ebeeff225da34006cbe6427638fadc
./.git/objects/ed/fd7e903f8f622f9a52542adfa077552608202d
./.git/objects/26/ef8e81bc27b4a67f251145a4f83782364fa9fa
./.git/HEAD
./.git/info/exclude
./.git/logs/HEAD
./.git/logs/refs/heads/master
./.git/description
./.git/hooks/commit-msg.sample
./.git/hooks/pre-rebase.sample
./.git/hooks/pre-commit.sample
./.git/hooks/applypatch-msg.sample
./.git/hooks/fsmonitor-watchman.sample
./.git/hooks/pre-receive.sample
./.git/hooks/prepare-commit-msg.sample
./.git/hooks/post-update.sample
./.git/hooks/pre-applypatch.sample
./.git/hooks/pre-push.sample
./.git/hooks/update.sample
./.git/refs/heads/master
./.git/index
./.git/COMMIT_EDITMSG

Git /fd7e90 and 26/ef8e8 are added to the object after commit. As can be seen from the archiving path and name of the file, git uses the SHA-1 algorithm to verify the contents of the file

There is also a COMMIT_EDITMSG that contains the comment information of the last submission

3. Use git cat-file to see where it came from

Git cat-file-p edfd7e90 commit git cat-file-p edfd7e90 commit git cat-file-p edfd7e90 commit git cat-file-p edfd7e90 commit git cat-file-p edfd7e90 commit git cat-file-p edfd7e90 61 de0edff4ebeeff225da34006cbe6427638fadc test. TXT git 26 ef8e8 cat - file - p / / terminal output tree 1612668900 + 0800 committers edfd7e903f8f622f9a52542adfa077552608202d author information the author information. 1612668900 + 0800

Ed /fd7e90 is a commit object. The tree attribute points to 26/ef8e8 and records the file operation, author, and committer information. 26/ef8e8 is a tree object. The BLOB attribute points to the BLOB 61/de0edf and records the file name. 61/de0edf is a BLOB object that records the contents of the file.

Three file relationships:



So now you see why object files are big

3.3 branch

Git branch: refs/heads/master

3.4 Git object model

According to the above analysis of 3.2, there are four types of ki objects in the Git system: 1.commit, which points to a tree and records the information of file operation, author and submitter; 2. Tree: Object relational tree, manage the relationship between tree and blob; 3. Blob: Save the contents of the file; 4. Tag: Submit.

3.5 Git lifecycle hooks

Git initializes a. Git file. If you do not use the hooks that are used with you, do not use them.

2. The hook is local because it is not committed to the repository, but is initialized by clone.

3. Hook classification:

The hook, role
pre-commit This is triggered before each Git Commit. A common use is to do ESLint validation of package.json in combination with Husky and lint-staged code
prepare-commit-msg Before Pre-Commit, generate commit information in the text editor is called, making it easy to modify automatically generated squash and merage commits
commit-msg The user input commit message is called, which is the commit message after COMMIT -M, and can be used to normalize the commit message
post-commit You can notify git of the result of the commit
post-checkout Git checkout is called
pre-rebase Run Git rebase before making changes
pre-receive Git push is executed after git push. It resides in a remote repository, with a server’s remote hook
update The pre – after the receive calls
post-receive Push is called when the push is successful, notifying the user of push

conclusion

Git and SVN are not easy to create. Welcome to STAR!