GIT -- command

GIT commands:

1. git help (view the usage of commands)
When you don't know which commands git has, you can use this command to view all commands that git has. If you want to see how to use a specific command, you can use git help <command> to check. <command> represents the command you want to view.


2. git log (view commit log)
usage: Just enter git log directly on the command line, and the initial state is to view the latest commit log. When viewing the commit log, z stands for viewing the record up, w stands for viewing the record down, and q stands for quitting.
git log is to view the commit log of all files;
git log <filename> , view the commit log of a file;
git log -p <filename> , view the specific content of each modification of a file;
git log -p -num , view the most recent For several commits, replace num with a specific number;
git log --stat , view all commit logs and file modifications for each commit.


3. git show (view the details of a commit)
usage: git show $id , $id represents the id of the commit, usually a long string of numbers and letters. If you want to know the corresponding id, you can use the above git log command to view.


4. git add (submit the modified file to the local staging area)
usage: git add <filename> , if only a single file is submitted, replace <filename> with the file name to be submitted, if you want to submit all modified files file, replace <filename> with a dot "." .


5. git rm (remove files from the repository)
Usage: git rm <filename> , this command deletes the file from the repository, that is, the file no longer exists after the commit; git rm <filename> --cached , this operation only deletes the file from the repository, but does not delete it file (usually unused).


6. git reset (restore files from the staging area)
usage: git reset <filename> , restore the specified file from the staging area to the local; git reset -- . , restore all the files in the staging area to the local.
git reset --hard , to revert to the state of the last commit.
git reset --hard HEAD~3: Roll back the last 3 commits.


7. git diff (compare files)
usage:
git diff <filename> , compare the differences between files and files in the staging area;
git diff $id1 $id2 , compare the differences between two commits;
git diff <branch1> <branch2>, Compare the differences between two branches;
git diff --staged , compare the differences between the staging area and the repository;
git diff --cached , compare the differences between the staging area and the repository;
git diff --stat , compare statistics (for local files).


8. git br (branch, git branch under mac)
usage:
git br -r , view the remote branch;
git br <newbranch> , create a new branch;
git br -v , to see the last commit of all branches;
git br --merged , to see the branches that have been merged into the current branch;
git br --no-merged , to see which branches have not been merged into the current branch;
git br -d <branchname> , delete a branch;
git br -D <branchname> force delete a branch, this command is similar to the cascading deletion of a database;
git br -vv , view the remote branch corresponding to the current local branch.


9. File update and submission
git pull, update all branches of the remote warehouse to the local and merge;
git pull origin master, update the master branch of the remote warehouse to the local and merge (the applicable scenario is not on the branch);
git fetch origin, Update the files of the remote warehouse to the local, no merge operation;
git merge origin/master , merge the remote master branch into the local;
git push , submit all files in the staging area;
git push origin master , push the local branch to the remote master branch;
git push origin <local_branch> , create a remote branch, origin is the name of the remote warehouse;
git push origin <local_branch>:<remote_branch> , create a remote branch;
git push origin :<remote_branch>, delete the local branch first (git br - d <branch>
git cherry-pick <commit id>, replace <commit id> with the corresponding commit version hashcode, this command commits a local version of the commit content to the current branch;
git branch --set-upstream-to=< remote>/<branch> <local-branch>, synchronize the local branch with the remote branch.


10. Check the remote warehouse information
git remote -v , check the remote server address and warehouse name;
git remote show origin , check the status of the remote server warehouse;
git remote add origin git@ github:robbin/robbin_site.git , add the remote warehouse address;
git remote set-url origin [email protected]:robbin/robbin_site.git , set the remote warehouse address (used to modify the remote warehouse address);
git remote rm <repository> # delete remote warehouse


11, create remote warehouse
git clone --bare robbin_site robbin_site.git , create a pure version warehouse with a versioned project;
scp -r my_project.git git@ git.csdn.net:~ , upload the pure warehouse to the server;
mkdir robbin_site.git && cd robbin_site.git && git --bare init , create a pure warehouse on the server;
git remote add origin [email protected]:robbin/robbin_site.git , set the remote warehouse address;
git push -u origin master , the client submits for the first time;
git push -u origin develop , submits the local develop branch to the remote develop branch for the first time , and track;
git remote set-head origin master # Set the HEAD of the remote warehouse to point to the master branch;


12. Generate ssh keys
1) Set the username git config --global user.name "yourname"
2) Set the mailbox git config - -global user.email "yourmail"
3) Generate key ssh-keygen -t rsa -C "yourmail"
4) Access test ssh [email protected]








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326300990&siteId=291194637