Version Control-Git server setup and use of Common commands-common git commands

Source: Internet
Author: User
Tags git commands

Version Control-Git server setup and use of Common commands-common git commands

Git is currently the most advanced distributed version control system in the world (none ). The following describes common Git commands.

I. Simple Edition

1. Create a version Library

git init

2. Add modifications and add files to the cache

git add

3. Compare file differences

git diff

4. view the warehouse status

git status

5. Submit changes (new) from the cache area to the version Library

git commit -m 'add a.txt'

6. view the submission log

git log (--pretty=oneline)

7. HEAD indicates the current version, HEAD ^ indicates the previous version, HEAD ^ indicates the previous version, and HEAD ~ 100 indicates 100 versions on the Internet

8. Update to the specified version (local modification not revoked)

Git reset -- hard HEAD ^ git reset -- hard 3628164 # differentiate a version of commit id.

9. view each command

git reflog

10. Undo workspace Modification

git checkout --file  

Corrected readme.txt by mistake and added it to the cache zone by git.

Git reset HEAD readme.txt # Return to the latest version and undo the git checkout --readme.txt modification in the cache # undo local modification

11. delete an object

Delete local file directly rm

Delete version library files

git rm a.txt git commit -m‘rm a.txt’

Delete files in the temporary storage area

Git rm -- cache a.txt git checkout HEAD(a.txt) # changes to the workspace and temporary storage area are cleared.

Ii. Upgrade

1. Add a remote Repository from github (origin is the default name of the remote repository and can be changed)

git remote add origin git@github.com:***/learngit.git

2. push all local modifications to the remote database (push uses the local master branch, and-u indicates that the master of the remote database is associated with the local master for the first time)

git push (-u) origin master

3. clone a repository (supporting ssh and https protocols, with ssh native and fastest)

git clone git@github.com:***/gitskills.git

4. Create a branch and switch to it (git encourages the use of the Branch)

git checkout -b dev

Equal to two Commands

git branch devgit checkout dev

5. Branch commands

View branch: git branch create branch: git branch <name> switch branch: git checkout <name> Create + switch branch: git checkout-B <name> merge a branch to the current branch: git merge <name> Delete branch: git branch-d (D) <name> Delete remote branch: git push origin: serverfix

6. View branch merge logs

git log –graphgit log --graph --pretty=oneline --abbrev-commit

7. branch management policies

The master is a stable version. It is developed on other branches and then stabilized and merged into the master.

When merging branches, you can use the -- no-ff parameter to merge them in normal mode. after merging, there are branches in history. It can be seen that merging has been performed, and fast forward (default) merging cannot be seen as having done merging

git merge --no-ff -m "merge with no-ff" devgit log --graph --pretty=oneline --abbrev-commit

8. Pending work scenarios

Git stash # pending git stash list # viewing git stash pop # restoring and deleting is equivalent to git stash apply & git stash drop

9. multi-person collaboration

Use the following command to push your modifications

git push origin branch-name

If the push fails, you must first use git pull to merge the local updates because of the remote branch/branch ratio. If there is a conflict in the merge, the conflict will be resolved and submitted locally; if there is no conflict or the conflict is resolved, use the following command to push it.

git push origin branch-name

If git pull prompts "no tracking information", the link between the local branch and the remote branch is not created.

git branch --set-upstream branch-name origin/branch-name

10. Tag operations

Git tag <name> # new tag. The default value is HEAD. You can specify commit idgit tag-a <tagname>-m "blablabla... "# specify the tag Information git tag-s <tagname>-m" blablabla... "# Use PGP to sign the Tag Name
Git tag # view all tags
Git show <tagname> # See the description
Git tag-d <tagname> # delete a tag locally
Git push origin <tagname> # push tags to a remote Repository
Git push origin -- tags # push all tags to a remote repository at a time

The label of the PGP signature cannot be forged because the PGP signature can be verified. The signature verification method is complex.

To delete tags of a remote repository, use

git tag -d <tagname>git push origin :refs/tags/<tagname>

Iii. Others

1. Ignore files

Create a special. gitignore file under the root directory of the Git workspace, and enter the file name to be ignored. Git will automatically ignore these files. We do not need to write the. gitignore file from the beginning. GitHub has prepared various configuration files for us. You only need to combine them to use them. All configuration files can be viewed online: https://github.com/github/gitignore

2. Configure aliases

git config --global alias.co checkoutgit config --global alias.ci commitgit config --global alias.br branch

The Git configuration files of Each repository are stored in the. git/config file.

4. Build a Git Server

For more information, see Liao Xuefeng official website http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

5. Gitolite construction tutorial

Reference official https://git-scm.com/book/zh/v1/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-Gitolite

1. Preparations

Git server git@10.16.4.14, git admin machine git@10.16.4.15

root@10.16.4.14$ useradd gitroot@10.16.4.14$ passwd gitroot@10.16.4.14$ su - gitadmin git@10.16.4.15root@10.16.4.15$ useradd gitroot@10.16.4.15$ passwd gitroot@10.16.4.15$ su - gitroot@10.16.4.15$ ssh-keygen -t -P ''

Send git. pub to git@10.16.4.14: 322/home

2. Use Admin

Git clone

git@10.16.4.15 git clone ssh://git@10.16.4.14:32200/gitolite-admin

Add user

1) Get the user's public ssh key, such as test@10.1.32.164.pub
2) store '1' pub to the git@10.16.4.15/home/git/gitolite-admin/keydir folder
3) Modify/home/git/gitolite-admin/conf/gitolite. conf and grant the repository permission of the '1' user.
4) git add & git commit-m'add user test... '& git push origin master
5) log onto the test@10.1.32.164 and git clone the repository in '3'

3. Permission Control

Please refer to the following link for more information: https://git-scm.com/book/zh/v1/-git-gitolite on the server.

Reference http://perthcharles.github.io/2015/08/24/setup-gitolite-service-git-1

4. Fixed Password Expiration issues

[git@Dev_10_16_4_15 gitolite-admin]$ git push origin master WARNING: Your password has expired.Password change required but no TTY available.fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.

Solution command

[root@Dev_10_16_4_14 ~]# chage -M 999 git

 

Original article, reprinted please note the original address http://www.cnblogs.com/lxmhhy/p/6038243.html

Add qq: 1130010617 for knowledge exchange and discussion. Thank you for your cooperation.

 

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.