git branch create, delete, switch, merger

1. look at git commands:

Check local branch git branch;

View remote branch git branch -r;

Handover branch git checkout -b agrochemical origin / agrochemical;

Check your branch git branch -a;

Rollback command: $ git reset --hard HEAD ^;

Fall back to the previous version $ git reset --hard HEAD ~ 3;

Prior to fall back to pre-submission three times, and so on;

Prior to fall back n commits $ git reset --hard commit_id;

Retreated / sha into the code specified commit $ git checkout commit ID;

View submit records: $ git log;

Strong push to a remote: $ git push origin HEAD --force

 

2.git delete the remote repository files, using the git rm command can be, there are two options:

One is the git rm --cached "File Path", do not delete the physical file, only the file is deleted from the cache; one is the git rm --f "File Path", not only delete the file from the cache, but also physical file will be deleted (will not recover to the trash).

If you have not accidentally commit files to the server you want to remove it, you can use: git rm - cached "Path + file name";

git commit -m "delete file" ;

git push; git rm -r "Path + file name";

git commit -m "delete file";

git push

 

3. The next step is to get down to business, you have to use at work:

First, create a branch and switch 1, create a new branch and switch to be submitted to the branch First, we start with the most simple to below demonstrates git branch create and switching the basic operation, follow these steps:

1 " git Branch <branch name>: the first to use git branch bugfix01, created a new branch bugfix01 named in the current branch is on the master branch.

2 " git Checkout <branch name>: then use git checkout bugfix01 command to switch to the new branch bugfix01 of our newly created.

3 " git commit: git commit command last used code to submit on the new branch.

4, create a branch and switch

1 "git checkout -b <branch name>: the first to use  git checkout -b bugfix02 command to create a new branch in the branch currently located bugfix01 and switch to the newly created bugfix02.

2 " git commit: Then you can use  git commit to commit in the new branch bugfix02.

 

Second, the branch merged with the deletion and conflict resolution

1, the combined branch -merge first use  is switched to the master branch git checkout master command.

Then use  git merge bugfix01 command bugfix01 branch changes fit into the master branch, to commit the new file after the successful combination will fit in, at the moment there will be a new commit number, it corresponds to the bottom of the C9 .

Then  git merge bugfix02, in the modified bugfix02 bonded into the master branch, merge commit number corresponding C10. Finally, it can still be submitted in the normal master branch.

 

2, remove the branches can be seen above, although bugfix01 and bugfix02 branch has been pushed into the master branch, but these two branches is still there.

If we do these two branches of the pointer, two pointers can be deleted branches: the first to use  git branch -d bugfix01 branch bugfix01 be deleted.

Then use  the branch bugfix02 delete git branch -d bugfix02.

Delete pointer operational point of view to just remove branches pointing to the number of commit, and does not remove its related submission number, commit the previous record can still be found in the log, you can still create a new branch on the commit.

If you want to delete the remote branch, then you have to use  $ git push origin --delete <branch name> a.

Guess you like

Origin www.cnblogs.com/jiangxiaobo/p/11096399.html
Recommended