git common commands

Situation: Now I want to create a temporary branch based on release-4.0 named release-4.1

switch to target branch

git checkout release-4.0

check if the branch is right

git branch

create a temporary branch named release-4.1

git checkout -b release-4.1

push local branch to remote. The remote branch is automatically created when you push it to the remote server

git push <remote-repo-name> <local-branch-name>:<remote-branch-name>

Warning: do not make the critical mistake of specifying only :, or the remote branch will be deleted if it has existed before

If the remote branch release-4.1 has already existed, you might want to keep the local branch to track the remote one, instead you should use:

git push -u <remote-repo-name> <local-branch-name>

Set tracking information for this branch

git branch --set-upstream-to=origin-repo/<branch> <your-local-branch>

Reset or revert a specific file to a specific version. Assuming the commit you want is abdc

git checkout abdc file/to/restore

Fetch specific file from other branch. For example fetch filepath/abc from release-1.0

git checkout release-1.0 -- filepath/abc

Ignore changed file to being listed as modified(temporarily)

git update-index --assume-unchanged <file>

To revert that ignorance use the following the command

git update-index --no-assume-unchanged <file>

Delete remote branch

git push origin --delete remote-branch-name

Modify comment which is not the latest one
1. Execute the below command, and next change the pick to reword, and then save it.

git rebase interactive the-parent-of-the-wrong-commit

猜你喜欢

转载自blog.csdn.net/zhangmagle125/article/details/51481850