Configure email address and name
git config--global user.name "Your name"
git config--global user.email "[Email protected]"
Turn the current directory into a git repository and build a. Git directory
Git init
File add, put staging area
git add *
File submission, submit staging area content; If the latest changes do not add, this change will not be committed
git commit-m "comment"
Show current submission Status
git status
View changes, support only plain text files
Git diff readme.txt
View history Log
git log--pretty=oneline
Back to previous version head^, the last version of head^^, up to 100 versions head~100
git reset--hard head^
Back to the specified version, commit_id only need to write the first few
git reset--hard commit_id
View commit_id Logs
Git reflog
Undo all changes to the file, returning to the state of the most recent commit or add
Undo changes back to the same state as the repository when no staging area is put in
After the file has been added to the staging area, it has been modified, and the undo changes are returned to the state added to the staging area
Git checkout--readme.txt
Undo changes to a file staging area
git Reset HEAD readme.txt
deleting files
git rm test.txt
Create SSH Key
Ssh-keygen-t rsa-c "[Email protected]"
Associate a remote Library
git remote add origin [email protected]:p Ath/repo-name.git
Push Branch content After association
Git push-u origin Branch-name
Push the latest changes after each local commit
Locally created branches are not visible to others if they are not pushed to remote
Git push Origin Branch-name
If the push fails because the remote branch is newer than your local update, you need to crawl the remote latest commit first
Git pull
If Git pull hints "No tracking information", then the association of local and remote branches needs to be established
Git branch--set-upstream branch-name origin/branch-name
To create a branch locally that corresponds to a remote branch
git checkout-b branch-name origin/branch-name
To view information for a remote library
Git remote-v
Clone a git repository
git clone [email protected]:p Ath/repo-name.git
Create a branch
Git branch Dev
Switch branches
git checkout Dev
Create a branch and switch to a branch
git checkout-b Dev
View Branches
Git branch
Git branch-a
Merges the specified branch to the current branch
git merge Dev
Disable Fast forward when merging branches to preserve branch information and create new commits
Git merge--no-ff-m "merge with No-ff" Dev
Delete Branch
git branch-d Dev
Forcibly deleting a branch that is not merged will lose the modification
Git branch-d feature1
To view the branch consolidation situation
git log--graph--pretty=oneline--abbrev-commit
Save the scene so you can do other things first, you can save them many times
Git stash
Recovery site, stash content is not deleted
Git stash Apply
You can delete stash content manually
git stash Drop
Restore the site while deleting stash content
Git stash pop
View Stash Content
git stash List
Revert to the specified stash
git stash apply [email protected]{0}
Create a label
git Tag v1.0
View Tags
git tag
Git show tagname
Create labels with instructions
git tag-a v0.1-m "version 0.1 released" commit_id
To label a commit_id.
git log--pretty=oneline--abbrev-commit
git tag v0.9 commit_id
Signing a label with the private key, using PGP signature, first to install GPG
git tag-s v0.2-m "signed version 0.2 released" commit_id
Delete a label
Git tag-d tagname
Push a tag to a remote
Git push Origin tagname
Push all the local labels that have not been pushed
Git push Origin--tags
To delete a remote label, delete it locally
Git tag-d v0.9
git push origin:refs/tags/v0.9
Let git show colors
git config--global color.ui true
to ignore certain files, you need to write a. gitignore file and submit the file
Thumbs.db
*.pyc
*.egg
Build
content/photos/
Configure aliases for the command,--global for the current user, and not for the current warehouse
You can view the aliases that have been added in the configuration file. git/config
The current user's git configuration file is in the. gitconfig file in the user directory
git config--global alias.st status
Git St
Configure the alias of the command to revoke the staging area modification
git config--global alias.unstage ' reset HEAD '
Git unstage test.py
Configure an alias for the command to display the last commit information
git config--global alias.last ' log-1 '
Git last
//Build a git private server
$ sudo apt-get install git
$ sudo adduser git
Collect all the public key id_rsa.pub files of all users who need to log in, put all public keys
Import into the/home/git/.ssh/authorized_keys file, one line at a
Select a directory as a git repository, such as/srv/sample.git, and enter the command in the/srv directory:
$ sudo git init--bare sample.git
Create a bare repository with no workspaces, because the GIT repository on the server is purely for sharing
the git repositories on the server usually end in. git. Then, change owner to git:
$ sudo chown-r git:git sample.git
the created git user is not allowed to log in to the shell, which can be done by editing the/etc/passwd file
git:x:1001:1001:,,,:/home/git:/bin/bash
instead:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
this way, git users can use git through ssh, but they can't log in to the shell
because the Git-shell we specify for git users automatically exits every time you log in
You can now clone a remote repository via the git clone command:
$ git clone [email protected]:/srv/sample.git
to conveniently manage the public key, use Gitosis
to be as perverted as SVN to control permissions, with Gitolite
Git Learning Notes