The use of source code control git

Source: Internet
Author: User
Tags git commands

One, Git----the local repository----1. Create a new local repository
    • Git init
2. Configure the warehouse ① tell git who you are.
    • git config user.name lnj
② tell git how to contact you.
    • git config user.email [email protected]
The above configuration is a one-time configuration that will be configured to the managed files. The following configuration in the Git folder is a one-way:
    • git config--global user.name lmj
    • git config--global user.email [email protected]
3. How to learn git commands <1>, git general instructions
    • Git Status View file status
    • git Add. Add files to "staging area"
    • git commit-m "comment" file name add File to "local repository"

注意:

<2>, if you do not add-M to the commit after the change, will automatically enter the Vim interface, ask us to enter the modification information
    • Press I on the keyboard to start typing
    • When you are finished, press ESC and then press: WQ
So: If later in the terminal to submit the best in the back plus-m<3>, 注意:
    • The add in Git is not the same as the add in SVN, only need add once in svn, and git will need to add after each new or modified
① Red is represented in the "work area"
    • To add a previous color
② Green code in "staging Area"
    • Color after adding to staging area
<4>, 注意:Git does not have shorthand instructions by default

注意:Custom shorthand directives are generally not recommended

    • Shorthand in Git is called an alias.
Aliases & Logs
    • $ git config alias.st status
    • $ git config alias.ci "commit-m"
<5>, viewing log
    • git log file name
    • 注意:The version number in Git is a "40-bit" hash value.
    • and the version number in SVN is an incremented integer.
Configure a colored log alias

git config--global alias.lg "log--color--graph--pretty=format: '%cred%h%creset-%c (yellow)%d%creset%s%cgreen (%CR)%c (bold blue) <%an>%creset '--abbrev-commit '

① The version that has been submitted
    • Git Reset-hard head^ back to previous version

      • Where-hard represents a forced reset
    • Git reset-hard version number (requires only the first 7 bits written)

② Not submitted
    • git checkout file name fallback to the last committed version
    • Git Reset-hard HEAD back to the last submitted version,

注意HEAD后面没有尖号^

c9ad690 [email protected]{0}: commit: main.c7026f99 [email protected]{1}: commit: 输出结果e950c89 [email protected]{2}: commit: 新增输入c7bf91c [email protected]{3}: commit: 添加变量cbd9e52 [email protected]{4}: commit: 删除print函数45ea44d [email protected]{5}: commit: 添加了printf函数0da06d8 [email protected]{6}: commit (initial): i
<6>, git reflog See all the changes (all versions) <7>, see where the files have been modified
    • git diff file name
      • If the show green represents the new
      • If the red indicates that the delete

----Remote Repository----
    • SVN needs a separate server
    • Git doesn't need: files, USB sticks, clouds, GitHub, Oschina ...
1. Create a new git remote repository
    • Git init-bare
    • 注意:This repository is just for managing code and not for developing
2. Project Manager initialize Project 2.1 clone an empty warehouse to a local
    • git clone/users/apple/desktop/working/company Remote repository
2.2 Ignore files and folders that do not need to be added to the version controller
    • . gitignore
    • 注意:Configuring the Ignore file only requires a search on GitHub. Gitignore Copy the code that someone else has written.
    • Configuration. Gitignore must be in and. Git hidden folder in the same level of directory
2.3 After you have generated the. gitignore file, you will also need to add the. gitignore file to version control
    • git Add. Gitignore
    • git commit. Gitignore-m ""
2.4 New Project
    • Source Conrol->commit commits the code to the local warehouse
    • SOURCE Conrol->push committing code to the remote repository

    • A branch is created by default in Git, which is called Origin/master, which is equivalent to the trunk in SVN

    • Professionals only need to write instructions in the Hooks folder in the GIT repository to complete automated testing (stress, automated, integration, smoke test 、。。。 )

    • As with SVN, if the code for the server repository is modified, we will also report the error when we submit the code.

    • Fetch first = = out of data
Summary: The biggest difference between git and svn
    • 1.git each modification will need to add
    • 2.git each computer has a warehouse
    • 3.git is submitted to the local repository before committing to the remote repository
----GitHub----Submit the code to GitHub via Xcode and put the warehouse on GitHub 1. Sign up for a GitHub account 2. Configure SSH Keys to seamlessly connect with GitHub as long as the Sshkeys is configured
    • Click on your nickname to visit our homepage
    • Click Settings in the home page (setting)
    • Click SSH Keys
    • Click Generating SSH keys
1. Check the local SSH keys
    • Under "User Directory" Ls-al ~/.ssh
2. If the folder does not exist, you need to manually create a
    • mkdir. SSH
3. Generate SSH keys based on GitHub tips 2
    • Execute under the. SSH Directory
    • Ssh-keygen-t rsa-c "[email protected]" After the input is completed, press ENTER continuously, know that there is a good graphics position
4. After generating public and private keys, enter
    • Ls-la to see if the build was successful
    • Id_rsa (private key) id_rsa.pub (public key)
5. Get the public key according to Tip 3
    • Pbcopy < ~/.ssh/id_rsa.pub
6. Click on setting-ssh key->add ssh key
    • Add the public key you just acquired.
7. Verify the public key according to the GitHub 4th step
    • Verify that the gray dots on the successful web page turn green
8. Open GitHub home page after copying to public key
    • Click Warehouse (repositories)
    • Then click New to GitHub to create the warehouse interface
9. Download an empty warehouse to a local location via the address provided by GitHub
    • Create a new project into the local warehouse folder
    • Submit code to GitHub with Xcode
    • Note: When a username password is required, the nickname displayed on GitHub is entered instead of the login account.

The use of source code control git

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.