-
GIT (Distributed version control system) editing
Git is a free, open source distributed version control system for agile and efficient processing of any or small or large project. [1] git's pronunciation is/g?t/. Git is an open source distributed version control system that can efficiently and rapidly handle project versioning from very small to very large. [2] Git is an open source version control software developed by Linus Torvalds to help manage the development of Linux kernels. Torvalds started to develop Git as a transitional solution to replace BitKeeper, which was previously the primary source code tool used by Linux kernel developers worldwide. Some in the open source community felt that BitKeeper's license was not appropriate for the open-source community, so Torvalds decided to work on a more flexible version control system. Although Git was originally developed to assist the Linux kernel development process, we have found that Git is also used in many other free software projects. For example, many FreeDesktop projects migrated to Git. Installation
Download git OSX version
Download git Windows edition
Download the git Linux version
Create a new warehouse
Create a new folder, open it, and then execute
git init
To create a new git repository.
Check out the Warehouse
Execute the following command to create a cloned version of the local repository:
git clone /path/to/repository
If this is the repository on the remote server, your command will look like this:
git clone [email protected]:/path/to/repository
Work flow
Your local repository consists of three "trees" maintained by git. The first one is yours 工作目录
, it holds the actual file, and the second is 缓存区(Index)
that it's like a cache area, temporarily saving your changes, HEAD
and finally, pointing to the results of your most recent commit.
Add and submit
You can schedule changes (add them to the cache) and use the following command:
git add <filename>
git add *
This is the first step in the Git basic workflow, using the following command to actually commit the changes:
git commit -m "代码提交信息"
Now, your changes have been submitted to HEAD, but not to your remote repository.
Push changes
Your changes are now in the HEAD of the local repository. Execute the following command to commit the changes to the remote repository:
git push origin master
You can replace master with any branch you want to push.
If you have not cloned an existing repository and want to connect your warehouse to a remote server, you can add it using the following command:
git remote add origin <server>
So you can push your changes to the server you added.
Branch
Branches are used to insulate the development of features. When you create a warehouse,master is "default." Develop on other branches, and then merge them onto the main branch when you are finished.
Create a branch called "feature_x" and Switch to the past:
git checkout -b feature_x
Switch back to the main branch:
git checkout master
Then delete the new branch:
git branch -d feature_x
Unless you push the branch to the remote repository, the branch is not visible to others :
git push origin <branch>
Update and merge
To update your local repository to the latest changes, do the following:
git pull
To get (fetch) in your working directory and Merge (merge) remote changes.
To merge other branches into your current branch (for example, Master), execute:
git merge <branch>
In both cases, Git will try to automatically merge the changes. Unfortunately, automatic merging is not always successful, and can lead to conflicts (conflicts). This time you need to modify these files to human flesh merge these conflicts (conflicts) . After you've changed, you'll need to execute the following commands to mark them as merged successfully:
git add <filename>
Before merging the changes, you can also use the following commands to view:
git diff <source_branch> <target_branch>
Label
It is recommended to create a label when the software is published. This is an old concept, also in SVN. You can execute the following command to create a label called 1.0.0 :
git tag 1.0.0 1b2e1d63ff
1b2e1d63ff is the first 10 characters of the commit ID you want to tag. Use the following command to get the commit ID:
git log
You can also use the submission ID for fewer of the first few, as long as it is unique.
Replace local changes
If you do something wrong (naturally, this is not possible), you can replace the local change with the following command:
git checkout -- <filename>
This command replaces the files in your working directory with the latest content in the HEAD. Changes that have been added to the cache, as well as new files, are unaffected.
If you want to discard all of your local changes and commits, you can get the latest version on the server and point your landlord branch to it:
git fetch origin
git reset --hard origin/master
Useful tips
Built-in graphical git:
gitk
Color git output:
git config color.ui true
When the history is displayed, only one line of comment information is displayed:
git config format.pretty oneline
To add files interactively to the buffer:
git add -i
git-User Guide