[Command] Git Git common scenarios and problem solving

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

How to modify the message of the latest commit

Use the following command to

git commit --amend

-amend not just modify the message of the latest commit the content but creates a temporary area generates a commit, then replace the current latest commit to a new generation that

How to modify the old commit message of

Use the command:

git rebase -i parent_commit_id

Then on cmd to be modified before the message was changed to reword, modify save and exit message

Wherein, rebase -i isolated state generate head pointers.
Because:
Process git rebase of work, is to use a separate head pointer. Based on the new base means rebase commit to change section commits. When it is treated, the base point of the HEAD commit, commit the case if no corresponding Branch, the head pointer is in a state of separation, and then again a new generation of a commit, when the last commit rebase been created, separated from the first end state, Git branch name change completed so that the base of pointing HEAD.

There is a thinking behind with rebase is a hash value of the parent commit, then how to modify the first commit of the message?

Further study may refer to
Git submit the correct posture: Commit message written guidelines
git how to modify the information already push the commit of

How organized into a plurality of consecutive commit a

Use the following command:

git rebase -i 开始commit [结束commit]

Then cmd to be modified before the message changed squash, save and exit can be added to an overall commit message in a new commit

When executing this command
If you do not specify an end commit, then ended commit defaults to the current date commit branch, it will automatically update the current branch pointed to commit after the rebase, if specified end commit, and ending commit instead of the current branch latest
commit then after the rebase will generate a free head ,, and the current branch pointed to commit not updated

How to commit a plurality of spaced merged into a commit

The above is a continuous multiple commit merged into one, then how will commit multiple discrete intervals combined into one?

Use the following command:

git rebase -i 最靠前需要合并的commit的父commit_id,如果是第一个commit,那么直接就是第一个commit_id

Then you want to merge several commit the message put together (next to the most forward of the need to merge commit), and the associated pre-commit cmd instead squash

Then save and exit.

Behind the rear resolve the conflict, first git add, --continue in git rebase

Diff HEAD staging area and pointed to a file

git diff --cached

Compare the differences of files of the work area and staging area

git diff
git diff -- filename (中间为两个’-’)

The staging area for the recovery of all files and documents stored as HEAD

git reset HEAD

The workspace content back to the content staging area

git checkout
git checkout – filename

Recovery staging area for the HEAD section of the same file

git reset HEAD – filename1 filename2

The elimination of several recent submission

git reset --hard commit_id

Differences between different specified file submitted

git diff 分支1 分支2 – filename
git diff 分支1commit 分支2commit – filename

The right to delete git repository file method

git rm filename

Development of temporary stopper how to deal with the urgent task

First contents of the file in the temporary area at hand aside and save up to do the urgent task
before git stash the contents of the temporary area are doing to keep the stash
and then do other urgent tasks
using the emergency task is completed:

git stash apply : stash列表中的信息还在,可以反复使用
git stash pop : stash列表中的信息不在了

For details, see
the detailed explanation of git stash

Git does not need to specify a file management

Reference
to ignore files and folders do not need to submit
the removal of the documents and the removal of trace files

Git command line URL Daquan

https://gist.github.com/guweigang/9848271

Guess you like

Origin blog.csdn.net/qq_42322103/article/details/95198902