Git commonly used commands and instructions

1, git commit code the commit

git the commit mainly to the staging area where changes to be submitted to the local repository. Every time we use the git commit command will generate a 40-bit hash value in the local repository. The hash value is also called commit-id.

commit-id when the rollback version is very useful, it is equivalent to a snapshot, you can come back here and git reset by a combination of commands at any time in the future.

1.1 git commit -m "message"

           this is more common usage, -m parameter representation can be entered directly behind the "message", if not -m parameter, then the message is not entered directly, but will call an editor generally it is to let you enter the vim the Message,

   the Message that is for us a brief description of the statements submitted. There is another way, when the message we want to submit a long or we want a clearer and more concise description, we can use this format, as follows:

        git the commit -m '

        message1

        message2

        Message3

1.2 git the commit -a -m "massage"

            other features such as -m parameter, add -a argument can execute all the trace file modification or deletion of files are submitted to the local repository, even if they have not been git add to add to the staging area, Note that the

   newly added file (ie not git file system management) can not be submitted to a local warehouse. General recommended not to use the -a parameter, submission of documents or use git add first want to change the normal added to the staging area, and then git commit to submit to the local repository.

    1.3 git commit --amend

            if we are not careful submitted a version of the code that we are not satisfied, and to push it up to the server, before the code is not our wish to merge a modified version satisfied, and if we do not want on the server abondon, then how do we do it?

         git commit --amend // also called an additional submission, it can not increase under a new commit-id of the new cases added to the modified code of a previous commit-id in

       (1) if the current repository recent a version of what we want to go that additional version, and this was the easiest, directly modify the work area code, and then git add, then you can git push to the server directly, without intermediate perform other operations such as git pull, etc.

       (2) If the repository is now the most recent version of a version that is not what we want to append to go, then we need at this time to fall back version of the repository version that we want to append, I want to version of what we want to fall back to version there are several ways

            1) the first version of that is we choose what we need from the server, directly picking, filed on the top right of the page in the server's management generally have a Download button click will bring up a drop-down box, choose one of the cherry-pick, the copy command,

     after running this command in our warehouse version corresponding directory, after the implementation, use git lo g -1 command, you can view the repository now become the most recent edition of this version we have just picking at this time and then modify the code directly in the workspace,

     conduct git add When you're done, then execute this git commit - amend command, after git push.

            2) Use gitk or other graphical interface tool, enter in a terminal gitk, carriage return, will pop up gitk graphical interface displays a section commit-id repository in the left part of the interface, at this time we need to select of that version, then right-click will bring up a

     selection menu, if it is in the master branch, then there will be one which is reset master branch to here, click on this will pop up a confirmation box called confirm reset, and select reset hard type of item, then click OK,

     close gitk graphical interface, back to the terminal, run git log -1 command, find the repository now has most recently submitted version is our hope that, this time again at work District directly modify the code, git add after he performed,

     then execute this command git commit --amend, after the Push git.

            3) If the version we know we need to be submitted with the n most recent version across the middle now, then we can directly git reset --hard HEAD ~ n order, git reset command has Comments on, then the command has completed,

     run git log -1 So we will find that the most recent version of the repository is now a version of what we need at this time and then modify the code directly in the workspace, a change after completing git add, git commit --amend then execute this command, after git push.

            4) we do not know if we need an intermediate version and the latest version now submitted through the n, then we can use git log to see the commit-id repository, find the commit-id we need, in the terminal execute git reset --hard commit-id,

     When this command is executed, run git log -1 command that we will find the most recent version of the repository is now a version of what we need at this time and then modify the code directly in the workspace, conduct git add When you're done, then perform this git commit --amend command, after the Push git.

 1.4 the commit git --help

       to view the help, there are many parameters have other effects, in general, to understand the three to meet our daily work developed

2. Check the current whether workspace file in the repository state warehouses have been modified)

git status

3, git ignore cancel a specified file

git-index Update --no-the ASSUME Unchanged config.conf-

4, the current version will fall back to the previous version with the following command:

git the RESET --hard the HEAD ^

5, fall back on two versions of

git reset - Hard the HEAD ^^

6, falls back to the specified version

git log // commit log display from the nearest to the farthest

git reset - -ha 1234567rd_commit_id // fall back to the specified version

7 to view the command history

git reflog

8, pulling the staging area file and replace the workspace file

git checkout-- <file>

9, tracking canceled, that file from the g In it out, no longer version tracking, but the files remain workspace.

git rm - - cached filename

10, see the workspace and repository inside the latest version of the difference between

git diff the HEAD - the Readme.txt

git diff command to compare the differences between files and staging area Snapshot current working directory, that is, after the modification has not scratch up changes in the content of

11, will work to put in the content repository staging area

git the Add the Readme.txt

 

12, it displays the status of the staging area and working directory

git status

13, to delete a file

git RM test.txt

14, from remote library clones project

git clone project addresses

15, create a branch, then switch to branch

git Checkout -b test_localhost

git Checkout command with the -b parameter indicates and switches, the equivalent of the following two commands:

git branch test_localhost // create a branch

git checkout test_localhost // switching branch

16, to view the current branch

git branch // Check local branch

git branch -r // Check remote branch

git branch -a // command lists all the branches of the current branch in front of a monogram number *

17, git merge command is used to specify the branch to merge the current branch

git merge dev

18, delete the local branch

git branch -d dev

If there unconsolidated work, you can not delete the branch.

git branch --no-merged // View unincorporated work

If you do want to delete the changes on the branch, can be enforced in uppercase delete option -D

19, dev delete remote branch

git the Push Origin --delete dev

20, handover branch

Git Checkout <name>

21 is, see the remote database information

git remote -v or git remote

22 is, push branches, that is, all local branch filed on the push to the remote repository. When pushed, to specify the local branch, so that, Git will branch to the branch pushed on the remote corresponding to the remote database:

Git Origin Master Push

To push the other branches, dev example, on changed:

Git Push Origin dev

23 is, pull take branch

git pull // If the current track has only one branch branch, even the remote host name can be omitted

pull remote branch: git pull origin dev

remote repository changes into the current branch. In the default mode, git pull git fetch is followed by git merge FETCH_HEAD acronym.

More specifically, git pull the given operating parameter git fetch, and calls git merge branch retrieved header into the current branch. Use --rebase, it runs git rebase instead of git merge.

The difference readme.txt readme.txt and buffer 24, to see the work area

Git diff the Readme.txt $

25, see the recent submission to the farthest record

git log

Guess you like

Origin www.cnblogs.com/wangdaren/p/11287578.html