Android Development _git Common commands

Source: Internet
Author: User

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

    • Topic: git Common commands
      -

1. Create and open a warehouse

mkdir xxx--Create xxx Empty directory

CD xxx--Open xxx Empty directory

2. Use the GIT init command to turn this directory into a repository that git can manage:

git init--initializing git repository

3. Use the command git add to tell git to add the file to the repository (in effect, add the file changes to staging area):

git Add file name

4. Use the command git commit to tell git to commit the file to the repository (in effect, commit all of the staging area's content to the current branch):

Git commit-m "meaningful additional Notes"

5. View the status of the workspace

git status

6. View the contents of the file being modified

Git diff

7. View the code's historical version number

git log

Git log–pretty=oneline--requires that version information be displayed only on one line

The version 8.HEAD is pointing to is the current version, so git allows us to travel between versions of history

Git reset–hard commit_id//commit_id, fill in the version ID, more ID to shuttle

or git reset–hard head^//forward one version
git reset–hard head^^//forward two versions

9. Review the command history to determine which version to return to in the future

Git reflog

10. Find out what Git's workspace (current partition) and staging area

11. Understand how git tracks changes, each modification, and if not add to staging area, it will not be added to the commit.

12. Undo Changes

The command git checkout–filename means to undo all changes to the filename file in the workspace, here are two things:

One is that filename has not been put into the staging area since it was modified, and now the undo changes go back to the same state as the repository;

One is that filename has been added to the staging area and modified, and now the undo changes go back to the state that was added to the staging area.

All in all, let this file go back to the state of the last git commit or git Add.

Scenario 1: When you mess up the contents of a file in your workspace and want to discard changes to the workspace directly, use the command git checkout–file.

Git checkout is actually replacing the workspace version with the version in the repository, which can be "one-click Restore", regardless of whether the workspace is modified or deleted.

Scenario 2: When you not only change the contents of a file in the workspace, but also add to the staging area, you want to discard the changes, in two steps, the first step with the command git reset HEAD
File, it goes back to scene 1, and the second step is done by scene 1.

Scenario 3: When an inappropriate modification to the repository has been submitted, you want to revoke this commit, and the version is rolled back, but only if it is not pushed to the remote library.

13. deleting files

git RM//is used to delete a file. If a file has been submitted to the repository, then you never have to worry about accidentally deleting it, but be careful that you can only recover files to the latest version and you will lose what you modified after the last commit.

14. Associating a local warehouse with a GitHub warehouse

1.git Init
2.git Add readme.md
3.git commit-m "First Commit"
4.git remote Add origin [email protected]:xxx/yyy.git
5.git Push-u Origin Master synchronizes the local repository to the GitHub repository.

After that, as long as the local commit, through the command: Git push origin master can push the latest changes of the local master branch to GitHub, do not need-U.

15. When multiple people collaborate on a project, each of us can use it as a clone by cloning it from a remote repository.

1.git Clone [Email protected],com:sysublackbear/xxxx.git

16. Create a branch and switch to a branch

1.git Checkout-b Dev
2.Switched to a new branch ' Dev '

Equivalent to:

1.git Branch Dev
2.git Checkout Dev
3.Switched to branch ' Dev '

To view branches:

1.git Branch Merge the secondary branch onto the main branch:

1.git Merge Dev

To delete a branch:

1.git branch-d Dev
2.Deleted Branch Dev (was fec145a).

17. Conflict resolution

When git cannot merge branches automatically, you must resolve conflicts first. After resolving the conflict, submit again, and the merge is complete.

You can see the branching merge diagram with the git log–graph command.

18.Bug Repair

When fixing a bug, we will fix it by creating a new bug branch, then merging and finally deleting;

When the work is not finished, first put the work site Git stash, and then to fix the bug, repair, then git stash pop, back to the job site.

19. Develop new features

To develop a new feature, it is best to create a new branch;

If you want to discard a branch that has not been merged, you can forcibly delete it by using git branch-d name.

20. Participate in the open source project first to clone a copy to the local

1. git clone [email protected]:michaelliao/bootstrap.git

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

Android Development _git Common commands

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.