Git basic usage

Source: Internet
Author: User
Tags commit hash reset tag name tagname ssh using git git clone

Developer Information Registration

git config user.name "Zhangle"

git config user.email zhangle@eastaeon.com

The Ex:author section shows the submitter information

Global configuration: git config--global user.name "xxx" three ways to download:

1.git protocol git clone git://192.168.110.230/library name
2.http protocol git clone http://192.168.110.230/gitweb/library name
3.SSH protocol git clone username@192.168.110.230:/home/git/library name

Screenshot of the following Git official document


For example:

git clone ssh://git@192.168.0.242/~/gitweb/alps. L0. MP2. V1_aeon6582_wt_l_inhouse

git clone ssh://git@192.168.0.242/github/alps. L0. P45.2_k35v1_64_op01_pre_inhouse Download steps:

1. Download the base version first in checkout

git clone ssh://git@192.168.0.22/home/git/< repository name >

The red part is that the same git server is the same.

< repository name >.git represents the repository naming of the project on the server.

2. Direct Access

git clone ssh://git@192.168.0.119/home/git/alps. Ics. Mp. V2.19-b Android_malata_k509-i10_thailand Android_malata_k509-i10_thailand

Get the latest Development Branch code

After Git clone is finished, the code obtained is the current branch of the repository on the server.

Ways to query the current branch: Git branch

Ex: Plus * represents the current location of branch

The parameters that Git branch often use are:

1.git branch–a Display all branch, including remote and local

2.git branch–r display only remote branch

If you want to switch to other branch, such as we want to cut the basic version branch work, on the server branch K50XV4 is the basic version of branch, so use:

git checkout–b k50xv4 origin/k50xv4

ORIGIN/K50XV4 represents the remote branch of the red font on the figure

Checkout will get a local branch k50xv4 like branch k50xv4 on the server after success.

git checkout Branchname


Create a new branch

Git branch newbranchname created and did not immediately switch to this branch, to use the

git checkout newbranchname switch to New branch, create and switch to new branch if not present

Recovery Workspace A file modification

git checkout <path> VI common commands (for handling merge conflicts):

DD//delete (but must be connected by 2 D)

U//fallback, that is, if you use DD, you can use U to reply

N//View Next

://Press this: Before you can enter a character, such as X

X//After pressing: And then pressing X to save the current changes save the changes to complete the conflict

VI//vi and the modified file name means that you want to modify the file, such as deleting a file conflict

Ctrl+r Redo the previous undo operation

Resolve Conflicts

git reset--hard HEAD//revert to the state of the commit that was last committed to the current branch

git fetch

git merge Origin/driver_youlitong_k502-pm910//merge

GIT branch--no-merged//See which files are not merged successfully

git status > Status.info//Import the current status information into the Status.info file (search unmerged)

Less status.info or more status.info//view information in Status.info file

VI mediatek/config/ztenj75_sz_cu_ics/projectconfig.mk//view edit resolve Conflict,/head Enter to view conflict, next n, delete a line of DD, save exit: X, do not save exit: q!

git add mediatek/config/ztenj75_sz_cu_ics/projectconfig.mk//upload conflict file

Git commit-m "fix Meger"//Submit

git merge origin/driver_youlitong_k502-pm910//merge again

Git whatchanged//View change history

Git push Origin android_hk_k501_77-w916:android_hk_k501_77-w91

Commit local changes to the remote server.

git push

$ GIT push origin Test:master

Submit local Test Branch as remote Master Branch

$ GIT push origin test:test

Submit the local test branch as a remote test branch

If you want to delete a remote branch. Similar to the above, if: The left branch is empty, then delete: The remote branch on the right.

$ git push origin:test

The test that you just submitted to the remote will be deleted, but it will be saved locally, so don't worry.

As an example:

git push origin:origin/android_hk_k501_77-w916

Because: The front is empty, so the branch origin/android_hk_k501_77-w916 and android_hk_k501_77-w916 that exist on the server now have only one, because the branch origin/android_hk_ K501_77-w916 was removed, but the local was still there.

Common errors: 1.error:failed to push some refs to ...

When you want to push the code to git, a prompt appears:

Error:failed to push some refs to ...

Dealing with "Non-fast-forward" errors

From time to time encounter this error while pushing:

$ GIT push origin master

To.. /remote/

! [Rejected] master, master (Non-fast forward)

Error:failed to push some refs to '. /remote/'

To prevent-losing history, Non-fast-forward updates were rejected

Merge the remote changes before pushing again. See the ' Non-fast forward '

section of ' Git push--help ' for details.

This situation is usually caused by the following reasons:
You can force Git-push to update when uploading changes, as long as you precede the branch name with a plus sign.
-deleted an already published commit with ' Git-reset--hard ', or
-Use ' Git-commit--amend ' to replace an already published submission, or
-use ' git-rebase ' to rebase an already published submission.
$ git push ssh://yourserver.com/~you/proj.git +master

Workaround:

Method 1: Use strong coverage to replace content in Git repositories with your local code

Git push-f

Method 2. First fetch git stuff to your local and then merge and push.

$ git fetch

$ git merge

The 2-sentence command is equivalent to

$ git pull

However, the following problems have arisen:

The above [branch "master"] is what needs to be clarified (. git/config) as follows

[branch "master"]

Remote = origin

Merge = Refs/heads/master

This is tantamount to telling git2 something:

1, when you are in Master branch, the default remote is origin.

2, when you use git pull on Master branch, you don't specify remote and branch, then git uses the default remote (that is, origin) to merge all the changes on the master branch

If you do not want to or do not edit the config file, you can enter the following command line on the bush:

$ git Config branch.master.remote origin

$ git config branch.master.merge refs/heads/master

Then git pull again. Finally git push your code.
2. Error:dst Refspec android_t600_liandai_s28a_w1_98m matches more than one.

Error:failed to push some refs to ' ssh://git@192.168.0.119/home/git/alps. JB2. Mp. V1.3 '

This problem occurs because the local tag and branch names are the same, or the remote has the same tag as the branch name, to remove the local and remote tags with the same name as the branch to be submitted, to continue the push.

git tag–d delete local and branch names with the same tag

git push origin:refs/tags/[tag name] Delete remote tag


3. Git–fatal:unable to create '/path/my_project/.git/index.lock ': File exists.

Fatal:unable to create '/path/my_proj/.git/index.lock ': File exists.

If no other git process are currently running, this probably means a
Git process crashed in this repository earlier. Make sure no other git
Process is running and remove the file manually to continue.

You can try to delete Index.lock.

Rm-f./.git/index.lock

4.error:src Refspec XXX matches more than one

When you manage your code with repo, you encounter error:src Refspec XXX matches more than one error, which is encountered when deleting a remote tag.

One is encountered when a tag is push to the server, and the two error hints are exactly the same. How to solve this problem, after the study found

To solve the method, the following will solve the method and share with you.

In the first case, the workaround for removing the remote branch is when you encounter this situation:

For example, when you delete the Testtag tag on the server, enter the following command

git push Origin:testtag

Tip error:src Refspec XXX matches more than one

Error:failed to push some refs to ' git@xxx:android/text.git '

The reason for this error is that there is a tag branch on the server which is the name of the Testtag, which has a branch branch.

That is, the tag branch and the branch branch have the same name, when executing the git push origin:testtag This command is not known to delete the

Therefore, the error is indicated. Workaround:

git push Origin:refs/tags/testtag

This is the branch that explicitly tells the server to delete the tag,

Delete Branch Branch

git push Origin:refs/heads/testtag

In the second case, there is a workaround to push a tag branch to the server when it is encountered:

Also the Testtag this tag branch, for example, push the tag branch to the server

Git push Origin Testtag

Tip: Error:src refspec XXX matches more than one

Error:failed to push some refs to ' git@xxx:android/text.git '

This error occurs mainly because there is also a branch branch named Testtag, which is not known to push the branch branch to

The server or the branch of the tag push to the server, if it is to push the tag branch to the server, then the branch branch is deleted, if the

Branch's branch push to the server will delete the tag's branch.

To delete a branch branch:

Git branch-d testtag

Ways to delete the tag branch:

git tag-d testtag git developers daily basic operations

(1) Synchronize local code with server command: Git pull Origin branch name (our current branch name is Br_dev)
(2) Modify the files that need to be modified to view the currently modified file commands are: Git status
(3) Add the modified file to the version tree:
A. single file git add filename
B. Adding all files under the working directory git add–a
(4) Commit the code to the local repository git commit–m "commit comment",

If the note is longer, you can also use the following command: Git commit enter your comments in the popup interface, press ctrl+x and then press Yes to save the changes
If you accidentally write the wrong note, use the command to modify the most recent commit comment git commit-amend
(5) After writing the note, you need to make a patch to the code to submit the person

The patch command is: Git format-patch origin changes the current modification to patch.
If you want to make only one commit a patch then the command is: git format-patch-1 commintid commit number
(6) Push local code to remote repository Git push Origin master
Origin is the source of code that can add its own default name to Origin
Master is the branch name of the remote repository, you can write the branch name according to the actual situation, the default is master git branch branch operation

(1) Create branch git branch branchname
Create a new branch based on a branch git branch newbranch oldbranch
Create a branch with a tag as a benchmark: Git branch branchname tagname
(2) Delete branch

Git branch–d branchname

Git branch-d can only delete branches that have been merged by the current branch. If you want to force a branch to be deleted, use git branch–d

Delete Remote branch: Git push origin: remote Branch name.
(3) switching branches

git checkout Branchname

Switch to the local branch, Branchname to the local branch name.

git checkout–b k50xv4 origin/k50xv4

Create a local branch based on the remote branch K50XV4
(4) Branch merging

Git merge requires a merged branch name –squash
This parameter represents merging all commits from another branch into a commit on the current branch, and then git commit–m "commit comment"
Merging branches but not committing: git merge--no-commit branchname
Picking merged Cherry-pick
git checkout Master

Git Cherry-pick The commit version number of other branches
(5) Branch Rename
Git branch–m oldbranchname newbranchname

git checkout

The main function is to move out of a specific version of a branch. The default is the head version of the move-out branch
Example:
git checkout master//Take out the master version of head.
git checkout tag_name//Remove the tag_name version on the current branch
git checkout master file_name//Discard current changes to file file_name
git checkout commit_id file_name//Fetch file file_name in commit_id Yes version. COMMIT_ID is the SHA value for Git commit.
$ git checkout--hello.rb
This command hello.rb the head out of the.
$ git checkout.
This command checks all modified files in the current directory from the head and restores it to the unmodified state.
Note: When using Git checkout, the changes will be overwritten if their corresponding files have been modified.

git log logs

View logs: Git whatchanged

git show HEAD//show update details for the latest version of the current branch//git show head^^, etc.

exit to look at the log: Ctrl + Z or Q

Git show Commitid//show specific details of a particular modification


git log Help

Parameter description:
- N (n is a positive integer) to view the last N commit information

$ git log-2 See the last 2 commit history

--filename filename for any file name to view the submission information for the specified file. (Note: The file name should be placed at the last position of the parameter, usually preceded by--separated by a space to indicate the file.) )

$ git log file1 file2 view commit record for File1 file File2 file
$ git log file/view commit records for all files under the file folder

--branchname branchname for any branch name, view the commit record on Mo branch. As above, it needs to be placed at the last position in the parameter. (Note: If the branch name is the same as the file name, you will be prompted with an error, the--option to specify whether the given parameter is a branch name or a file name.) Example: There is a file named V1 in the current branch, and there is a branch named V1:

$ git Log v1--At this point the V1 represents the branch name
$ git log--V1 at this time the V1 represents a file named V1
$ git log v1--V1

tagname or branchame query the commit record information in the specified label/branch

$ git log v1.0. Query the Commit history from v1.0 (not including v1.0) $ git log test: Master queries the commit record in the master branch but does not contain the test branch record
$ git log master: Test commits records in the test branch but does not include the master branch record
$ git log master...test queries the commit record in the master or Test branch.
$ git log test--not Master Block Master Branch

query log according to commit

$ git log commit query commit before the record containing the commit
$ git log commit1 commit2 query between Commit1 and Commit2 records, including Commit1 and Commit2
$ gi T log commit1..commit2 Ibid, but does not include commit1

Where commit can be a shorthand mode for committing hashes, or you can use head instead. The HEAD represents the last commit, and head^ is the last committed parent, equivalent to the Head~1,head~2 delegate's second penultimate submission
--pretty
Displays the log information in the specified format, with the options: Oneline,short,medium,full,fuller,email,raw and Format:<string>, which, by default, medium, can be modified by modifying the configuration file to specify the default
Way.

$ git log (--pretty=) oneline

Common format options:

Options       description

%h       Commit object ( Commit) The full hash string

%h       The short hash string for the Commit object

%t      The full hash string for the   tree object (tree)

%t       short hash string for the tree object

%p        the full hash string of the parent object (parent)

%p       A short hash string for the parent object

%an       author (author) name

%ae      Author's e-mail address

%ad       Author revision date (can be customized with  -date=  options)

%ar      The author's revision date, showing how long ago the

%CN      Submitter (committer) name

%ce      The submitter's e-mail address

%cd      Submission Date

%cr      The submission date and how long ago it was displayed

%s       Submission Instructions

Note: The author refers to the person who last modified the document, and the submitter refers to the person who submitted the document.

$ git log--pretty=format: "%an%ae%ad%cn%ce%cd%cr%s"--graph

--mergs View all the merged commit history

--no-merges View all submissions that have not been merged

--author=someonet Query the submission record for the specified author

$ git log--author=gbyukg

--since,--affter Only show commits after a specified time (not including the current date)

--until,--before Show only commits before the specified time (contains the current date)

$ git log--before={3,weeks,ago}--after={2010-04-18}

--grep Filtering the submission log by submitting the description information

$ git log--grep=hotfix This command will list all the submission records that contain the description of the submission for the hotfix word

Note: If you want to use both--grep and--author, you must attach a--all-match parameter.

- S retrieves the specified commit log by querying the change contents of the file Note: the-S does not have a "=", and there is no space between the contents of the query

$ git log--snew

- P View patch information at commit

$ git log-p--no-merges-2

--stat List the number of modified rows for a file
--sortstat only displays the last number of rows in--stat Modify add removed statistics
--graph list submission records in a simple graphical way
--abbrev-commit displays only the first few characters of the SHA-1, not all 40 characters.
--relative-date uses a shorter relative time display (for example, "2 weeks Ago").
--name-only Displays the modified list of files only after the information is submitted.
--name-status Displays a list of new, modified, and deleted files.

GIT Blame
to view each part of the file modification details

$git Blame index.php

Example:

Git log-2-P displays log and diff for the last two commits

git log-p review log details and changes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.