git common commands to organize and set git to use vim as an editor

1. Execute the command in the local warehouse: git init initializes the local warehouse

2. Create a project on a code hosting platform such as GitHub, copy the link

3. Execute the command in the local warehouse: git remote add origin + remote warehouse link

4、git pull

5、git --set-upstream=origin/master

6. git checkout -b develop creates a development branch

7、git --set-upstream=origin/develop

8. git push -u origin develop; add the "-u" parameter to the first submission to associate the local develop branch with the remote develop branch.

9. You can then develop on this branch

11. Generate ssh key under Windows system: just open git bash and enter the command: ssh-keygen -t rsa -C "[email protected]" to generate it, which is the same as the Linux system operation.

12. Ignore the files in the local warehouse when git commits: Create a .gitignore file in the local warehouse, and add rules for the files to be filtered in it. Regular matching can be used, and each rule has its own line.

Remark:

/target/ : filter file settings, which means to filter this folder

*.mdb , *.ldb , *.sln means to filter a certain type of file
/mtk/do.c , /mtk/if.h means to filter specific files under a certain file
 !*.c , !/dir/subdir The beginning of /! indicates that
 *.[oa] is not filtered. Wildcards are supported: all files in the repo with the extension .o or .a are filtered.


Set up git to use vim as editor

Git uses emacs as the editor by default, we can use VIM in any of the following ways

  1. Set in git config core.editor
    git config --global core.editor "vim"
  2. Set in environment variables GIT_EDITOR
    export GIT_EDITOR=vim
  3. If you want not only git to use vim, but also other programs, you can set it as follows: 
    Note: The following two standard environment variables are not necessary, but some programs will not use the more popular VISUAL, but use EDITOR, so Best to add both.
export VISUAL=vim
export EDITOR="$VISUAL"

--wait In addition, if you want to be very cool, you can use more advanced functions, that is, add parameters to ./.gitconfig .

[core]
    editor = 'subl' --wait



Use git to merge multiple commits

Suppose you want to merge the last 2 commits, you can do it as follows:

1. git rebase –i HEAD~2 After

    running the command, the following will appear:

    1

2. Pick the second Modify it to squash or s, and then enter ":wq" to exit.

3. At this time, git will automatically merge the second commit into the first one. And prompt to enter a new message (that is, we often say comments), as follows:

    2

4. Edit and enter the new message, and then enter ":wq" to exit

5. At this time, the last two submissions in the local (HEAD) have been merged for one. git log can be viewed.

6. If you need to submit to the remote, run git push --force origin master.


---------------------------

git log:

Commit A

Commit B

Commit C

Commit D

Commit O


For example, to merge ABCD into a commit

git rebase - i Commit O

sets s in front of BCD to

exit the rebase, and when editing the commit,


it becomes

Commit X

Commit O



merges the n commits on branch A to branch B

git merge --squash A



git commit commit times record merge

1. Execute on your own branch: git log

2, then copy the last uniquely generated long string of identifiers you want to merge

3. : q Go back to your own branch and execute: git rebase -- interactive "long string identifier copied in the log"

4. Edit mode (i), according to the following prompts, make corresponding modifications (generally: modify the pick before the corresponding comit log to f), then save and exit


5. Execute git push -f origin "your own branch name"

git log to see which commit you want to start rebase from, such as xxstart00; this commit xxstart00 will not be

affected

. clear.

The first commit cannot be changed to squash, otherwise the following prompt will appear:

Cannot 'squash' without a previous commit

Merge whoever wants to merge next, change pick to squash

, save and exit the editing, and automatically switch to the editing interface of commit; this It is the merged commits







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324688755&siteId=291194637