Git Common Operations Command collection: 1) Remote Warehouse related command checkout warehouse: $ git clone git://github.com/jquery/jquery.git view remote repository: $ git remote-v Add remote repository: $ git remotely add [ Name] [url] Delete remote repository: Git remote RM [name] Modify remote repository: $ git remote set-url--push [name] [Newurl] Pull remote repository: git fetch [remotename] [ Localbranchname] Push remote repository: $ git push [remotename] [localbranchname] Force push change: $ git push--force origin master* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows: $ GIT push origin test:master//submit local Test branch as remote Maste R Branch $ Git push origin test:test//submit local test branch as Remote Test branch 2) Branch (branch) operation related commands view local branch: $ git Branch View remote branch: Git Bran Ch-r (if you still can't see Git fetch origin first) create a local branch: Git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created: git checkout [name] creates a new branch and immediately switches To the new branch: $ git checkout-b [name] Check out remote branch directly: Git checkout-b [name] [remotename] (e.g. git checkout-b mynewbranch origin/dragon) Delete Except branch: $ git branch-d [name]-----D option can only delete branches that have already joined the merge and cannot be deleted for branches that do not have a merge. If you want to force the deletion of a branch, you can merge the branch with the-D option: git merge [name]----Merge the branch with the name [name] with the current branch and merge the last 2 commits: $ git rebase-i HEAD~2----Number 2 can be modified as needed (if you need to commit to the remote $ GIT push-f Origin master use it carefully!) Create remote branch (local branch push to remote): Git push origin [name] Delete remote branch: git push origin:heads/[name] or GIT push origin: [name] Modify branch name: Git Branch-m <old_branch_name> <new_branch_name> Create empty branch: (Remember to submit your current branch's changes before executing the command, otherwise you will be forced to delete the clean without regret) $ git Symbolic-ref HEAD refs/heads/[name]$ rm. git/index$ git clean-fdx3) version (tag) operation related Commands view version: $ git tag Create version: $ git tag [name] Delete version: $ Git tag-d [name] View remote version: $ git tag-r Create remote version (local version push to remote): Git push origin [name] Delete remote version: $ git push origin:refs/tags/[name ] Merge the remote repository tag to Local: Git pull origin--tags upload local tag to remote repository: $ Git push origin--tags Create annotated tag:$ git tag-a [name]-M ' YourMessage ' 4) Sub-module (submodule) Related Operations Command add Submodule: $ git submodule add [url] [path] such as: $ git submodule add git://github.com/soberh/ui-libs.git Src/main/webapp/ui-libs initialization submodule: $ git submodule init----run only once when the warehouse is first checked out update submodule: $ git submodule update---- Each time you update or switch a branch, you need to run the delete submodule: (4 steps away) 1) $ git RM--cached [path] 2) Edit the ". Gitmodules" file, delete the associated configuration node of the Submodule 3) Edit the ". Git/config" file,Delete the associated configuration node of the Submodule 4) manually delete the remaining sub-module directory 5) Ignore some files, folders do not submit in the repository root directory to create a file named ". Gitignore", write the unwanted folder name or file, each element occupies one line, such as targetbin*. DB6) Regret medicine Delete files that are not versioned in the current repository: $ git clean-f recovery repository to last commit status: $ git reset--hard rollback all content to previous version: $ git reset head^ Fallback a.py version of this file to the previous version: $ git reset head^ a.py fallback to a version: Git reset 057d fallback the local state to the same as remote: $ git reset–hard origin/master forward back to 3 versions: $ git reset–soft head~3 Modify the last commit log: $ git commit--amend7) git one-click to push multiple remote warehouses to edit the. git/config file for the local repository: [Remote "all"] url = [em ail protected]:d ragon/test.git url = [email protected]:d ragon/test.git this way, using git push all can push to multiple remote warehouses in one click. 8) Cache authentication information $ git config credential.helper cache9) View commit log to view the author of each line in the file, latest change submission and commit time $ git blame [filename]git common actions command-rongjih -Have your own dreams, follow the call of the heart. View warehouse History There are three options that should be known. --oneline-compression mode, which displays a streamlined commit hash code and commit information next to each commit, shown on a single line. --graph-graphical mode, which uses this option to draw a historical information representation of the text format on the left side of the output. This option is not available if you are viewing the history of a single branch. --all-Show history of all branches after combining these options, the following: Git common operations Command-rongjih-Have your own dream, follow the call of the heart use the $ git log--oneline--graph--name-status to see both the intro Log information, you can also see which files have been changed, double benefit: git common operations Command-Rongjih-Have your own dream, follow the call of the heart 10) selective merging-this feature is best, not one cherry-pick can pick up a separate commit from a different branch and merge it with your current branch. If you are dealing with two or more branches in parallel, you may find a bug in all branches. If you resolve it in a branch, you can use the Cherry-pick command to commit it to another branch without messing up other files or commits. $ git cherry-pick [commithash]11] STASH uncommitted changes are modifying a bug or feature and are suddenly asked to show work. And now the work is not enough to submit, this stage can not be demonstrated (not to go back to the change). In this case, git stash can do a favor. Stash essentially takes all the changes and stores them for future use. $ git stash Check stash list: $ git stash lists want to release stash and redo uncommitted changes, apply stash:$ git stash apply if you just want to leave the Apply stash, Add a specific identifier to apply: $ git stash apply [email protected]{0}12) multiple modifications after split commit-partial changes to the staging file in general, creating an attribute-based commit is a good practice, This means that each commit must represent the creation of a new feature or a bug fix. What if you fixed two bugs, or added multiple new features but didn't commit the changes? In this case, you can put these changes in one commit. But a better approach would be to put the file on hold (stage) and submit it separately. For example, you have made several changes to a file and want to submit them separately. In this case, you can add the-p parameter to the add command $ git add-p [filename]13) to compress multiple commits using the rebase command to compress multiple commits into a single git rebase-i head~[number_of_commits ] If you want to compress the last two commits, you need to run the following command: Git rebase-i head~2docs:http://git-scm.com/book/en/v2/git-branching-rebasing14) diff view $ git diff--name-status head~2 head~3<--get a list of all changed files between two versions $ git diff head head~1 <--view differences between last two commits $ git diff head head~2 <--view differences between 1th and 3rd commits ^-Represents the parent commit, ^n represents the nth parent commit, ^ equivalent to ^1 git root: ^ and ~ The difference-the analysis is in place ~-Represents a continuous commit, ~n equivalent to a continuous nth commit $ git diff master. Test <--Compare differences between two branches $ git diff master...test <--compare master, test's Common parent branch and test Branch difference $ git diff test <--compare current working directory with T EST branching difference $ git diff head <--compare current working directory with last commit difference $ git diff head--./lib <--Compare the current working directory of the Lib directory with the last commit difference $ git diff--stat <--statistics on what files have been changed, how many lines have been changed $ git diff--cached <--See what to commit on next commit (staged, add to index) git for Windows Chinese garbled problem (1.9.4-previ ew20140611) git log shows the file name garbled execution "git Config–global core.quotepath false" can be resolved. Core.quotepath set to False, the characters above 0x80 will not be quote, Chinese will show normal. Pre-FIX: Git common commands-rongjih-Have your own dream, follow the call of the heart FIX: Git commands-rongjih-have their own dreams, follow the call of the heart the LS command displays the Chinese name garbled instead of "LS--show-control-chars "Command instead of the simple" ls "command. or edit .../git/etc/git-completion.bash, add a line alias ls= "Ls–show-control-chars"
Git common commands