Several useful Git commands that you may not know are useful.

Source: Internet
Author: User
Tags git commands

Several useful Git commands that you may not know are useful.
1. Export the last modified file submitted

I have been using this command to regularly send it to others for review/consolidation. This command exports the recently submitted modified files to a zip file.

1 git archive -o ../updated.zip HEAD $(git diff --name-only HEAD^)

 

2. Export the files modified between the two commits

Similarly, if you need to export files modified between two commits, you can use this one.

1 git archive -o ../latest.zip NEW_COMMIT_ID_HERE $(git diff --name-only OLD_COMMIT_ID_HERE NEW_COMMIT_ID_HERE)

 

3. clone a specific remote Branch

If you want to clone a specific branch from a remote repository, this command is useful to you:

123 git init git remote add -t BRANCH_NAME_HERE -f origin REMOTE_REPO_URL_PATH_HERE git checkout BRANCH_NAME_HERE

 

4. Apply patches from irrelevant local warehouses

If you need to apply from some other irrelevant databases submitted to the local repository, here is a quick method:

1 git --git-dir=PATH_TO_OTHER_REPOSITORY_HERE/.git format-patch -k -1 --stdout COMMIT_HASH_ID_HERE| git am -3 -k

 

5. Check whether your branch changes are part of another branch.

The cherry command allows you to check whether your branch changes exist in other branches. It displays the changes to the current branch relative to the given branch, and prompts whether to submit or merge with + or. + Indicates that the branch does not exist, and-indicates that the branch exists.

123 git cherry -v OTHER_BRANCH_NAME_HERE #For example: to check with master branch git cherry -v master

 

6. Start a new branch with no history

Sometimes, you need to start a new branch and discard historical information. For example, you want to put code in the public domain (Open Source) and do not want to share historical information.

1 git checkout --orphan NEW_BRANCH_NAME_HERE

 

7. Check the file from other branches without switching the branch

The following command retrieves files from other branches without switching the branches.

1 git checkout BRANCH_NAME_HERE -- PATH_TO_FILE_IN_BRANCH_HERE

 

8. Ignore modifications to the trace file

If you work in a team, they all work in the same branch, and you need to read/Merge files frequently. But sometimes you reset the specific configuration of your environment, and you have to change it every time after merging. With this command, you can ignore the changes to a specific file:

1 git update-index --assume-unchanged PATH_TO_FILE_HERE

 

9. Check whether the submitted changes are part of the released version.

This name-rev Command tells you where to submit the latest version. With this, you can check whether your changes are part of the released version.

1 git name-rev --name-only COMMIT_HASH_HERE

 

10. Replace merge with the pull rebase operation

If the team you work on is working on the same branch, you need to get/merge or pull it frequently. When the git record and merge commit for Branch merge are displayed, the function branch is merged into the trunk. However, when multiple team members work in the same branch, frequent merging leads to confusion caused by messages merged in logs. Therefore, you can use pull rebase to clear unnecessary merged messages in history.

1 git config branch.BRANCH_NAME_HERE.rebase true

In addition, you can configure a specific branch to always combine:

1 git pull --rebase 

Related Article

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.