Git compile installation and common commands =========================================: compiling installation and setting 1.1: Introduction GitHub website address (download source package): https://github.com/git/ Git.git git downloads on systems such as Windows Mac: Https://git-scm.com/downloads 1.2: Dependencies (resolving common dependencies) ~]# yum-y install GCC opens SL Openssl-devel Curl Curl-devel unzip Perl perl-devel expat Expat-devel zlib zlib-devel asciidoc xmlto gettext-devel Open
Ssh-clients ~]# yum-y Install openssh-clients # Ssh-keygen appears-bash:ssh:command not found workaround 1.3: Compile Installation Mode one: ~]# make prefix=/usr/local/git all doc ~]# make prefix=/usr/local/git install Install-doc
tml mode two: ~]# yum-y install autoconf ~]# make configure or autoconf # Note: Generate Configure file ~]#./configure--prefix=/usr/local/git ~]# make all doc ~]# make install Install-doc ML mode three: ~]# yum-y install git # install git ~]# yum-y Install # Install git all packages, not necessarily 1.4: ring Border configuration ~]# echo ' Export PATH=/usr/local/git/bin: $PATH ' >/etc/profile.d/git.sh ~]#. /etc/profile.d/git.sh ~]# git--version # View version 1.5:man document configuration ~]# vim/etc/man_db.conf Mandatory_manpath /usr/local/git/share/man View Help format one: ~]# git assist init format two: ~]# man git -init 1.6:ssh User, permissions, Server identity authentication, initialization warehouse and pull Warehouse 1: Add User: ~]# useradd git 2: Permissions (User mix user is git):/home/git/.s SH permission is: 700/home/git/.ssh/authorized_keys permission is: ~]# mkdir/home/git/.ssh ~]# chmod 700/home/git/.ssh ~]# Touch/home/git/.ssh/authorized_keys ~]# chmod 600/home/git/.ssh/authoriz Ed_keys ~]# chown-r git:git/home/git/.ssh # Note: Id_rsa permission is 644 3: Service
Identity authentication (Authorized_keys): The local public key id_rsa.pub inside the content to add to the/home/git/.ssh/authorized_keys, one line, you can add more than one public key, git operation no longer need a password. 4: Initialize the Warehouse: (at the end of. Git) create an empty project ~]# Cd/home/git # Enter git home directory ~]# git init--bare useryx.git # for example git init--bare warehouse name. Git Project has There is content ~]# git init # CD enters the project for initialization ~]# git clone--bare directory name repository. Git # For example: Git clone--bare Useryx useryx.git # Warehouse outside Execution 5: Modify the Warehouse user group for git ~]# chown git:git useryx.g It 6: Pull warehouse ~]# git clone [ssh://] username @ Address: warehouse name. Git # for example: Git clone git@192.168.31.73:useryx.gi
T or a file in the home directory like git clone git@192.168.31.73:/home/git/dir/a.git 1.7: Prohibit SSH user login, you can not set. ~]# vim/etc/passwd # Modify git user login Shell 1:/sbin/nologin not allowed to log on using Linux system git:x:1001:1001::/home/git:/
Sbin/nologin 2:/usr/local/git/bin/git-shell,which git-shell View the command location using the GIT service Git-shell. Git:x:1001:1001::/home/git:/usr/local/git/bin/git-shell Two: Client initialization Configuration 2.1: The client generates the public and private key Ssh-keygen (switches to the user who needs to generate the public and private key) ~]#
Su-git # Switch to git user ~]# Ssh-keygen # using the default RSA algorithm, 2048 length ~]# ssh-keygen-t rsa-b 4096-c ' git@aliyun.com '-P ' 3a/jd3v1wq6m1lrao+qc4bchb2w3synstg3ct1gs ' #-T specified algorithm #-C Add a comment #-B Specify the encryption length, default is 2048, 4096 #-P is recommended for use with cryptographic cipher string ~]# OpenSSL rand-base64 30 # 30
To generate string length # Use Ssh-keygen to follow the prompts, or you can enter directly. 2.2: Set user name and mailbox ~}# git config--global user.name "username" ~}# git config--global user.email "Mailbox @aliyun.com" 2.3: Initialize Tim
Add Folder 1: Create a new version library (normal process operation) git clone git@192.168.18.35:useryx.git cd Useryx Touch readme.md git add readme.md git commit-m "add README" Git push-u Origin master 2: Existing folders or git warehouse CDs
Useryx git init git remote add origin git@192.168.18.35:useryx.git git Add. Git commit-m ' Initialize ' Git push-u origin master 2.4: View the default profile ~]# git config--list or git config--l 2.5: Do not update files (. Gitgmore) ~]# find./-name. Gitignore # Lookup. gitignore file ~]# found./-name. gitignore-deLete # Delete. gitignore file # Files or directories that are not updated are placed in this file 2.6: Local clones ~]# git clone file://root/test/tmp/test ~]# git Clone Test/tmp/test # Local Git Project Clone III: Base Action 3.1: Add the file (add) ~]# git add filename # Adding a file ~]# gi T Add. or git add-a # Add current directory All file 3.2: Delete file (rm) ~]# RM # Delete file but not delete index ~]# git rm-f
FileName # uncommitted need-F delete ~]# git rm filename # delete file and delete index ~]# git rm--cached File # Delete index, change to an untraceable state ~]# git cat-file-p hash code # View File Contents 3.3: Modify file (mv) ~]# MV # Index Add new file, original The index to be retained. Submit with error ~]# git mv filename NewFileName # modify file at the same time modify Index 3.4: Index file Add to Snapshot (commit) ~]# git commit-m ' comment ' ~]# git
Commit-am ' comments ' # Add file and submit Comment 3.5: status ~]# git Status 3.6: File tracking traced (tracked) ~]# git ls-files
Untraceable (igored) ~]# git ls-files-o ignored (untracked): View file. Gitignore 3.7: Submit and pull ~]# git pull # Pull: From remote Get Latest version to local, does not automatically merge ~]# git fetch # Pull: From remote Get Latest version to local, will automatically merge ~]# git push ori Gin Master # Commit: Push local to remote main branch, 3.8: Log (log) ~]# git log ~]# git log--oneline # line display, short form ~]# git log--graph # tree figure ~]# git log--pretty=oneline--abbrev-commit 3.9: File comparison different ~]# git diff filename1 file Name2 # Compare files ~]# git diff dev # compare current branch with Main branch 3.9: Undo operation (Reset) 1:git reset–mixed <commit Id> <filename>: This is the default, it is back to a version, only retain the source code, rollback commit and index information 2:git reset–soft <commit id> <filename> Rollback commit information, keep index, if you want to submit, direct commit 3:git Reset–hard <commit id> <filename>: Back to a full version, the local source will become the previous version of the Content head: The most recent submission for the current branch Orig_head: When merging, the newly generated commit is saved in this reference head^ the previous time, the working directory is unaffected ^ back to the previous ~<n> back several times, equal to
Continuous head^ ~]# git reset--hard orig_head # before the rollback commit status four: Branch 3.1: View and new branch ~]# git branch--all ~]# git branch--lisT 3.:2: Create and Toggle branch ~]# git Branch <branch> # Create branch (based on current branch) ~]# git branch &L T;branch>