1. What is your favorite Git command is
Personally like git add -p.
this change increases the "patch mode", which is a built-in command line program. It iterates through each change, and ask for confirmation whether to execute them.
This command forces the change we slow down and check the file. As a developer, we often rush to submit sometimes, I myself so often, finished the run git add .
only to find the debugging code also submitted go up.
2. Why do you prefer to directly use the command git
As a developer, we often use other commands to do other things, not bad with the git
commands to do things.
In addition, the git
command is very short, very easy to learn and use the command to learn the git
workflow, which also indirectly improve the development process.
3. How to use the stage
command
stage
A add .
built-in alias.
4. How to save the changes in the branch and checkout
to other branches
Therefore, you can use git stash
to change or submit WIP temporary storage, the purpose is to have the environment before unmodified. For me personally, I prefer to use WIP submitted instead stash
, because they are easier reference and sharing.
WIP = Work in Progress
R & D in the code you want to store it, but also to avoid the development of the code are merged, the development will create a branch of WIP
WIP MR
WIP MR implication is that the merger request in the course of work, we have to avoid is a GitLab in MR technology are merged before the ready. Only need to add WIP:
at the beginning of MR's title, it will not be consolidated unless you WIP:
delete it.
5. When to use git stash
Found that a class is redundant, would delete it worries about the future need to see its code and want to save it but do not want to add a dirty submitted. Then you can consider git stash
.
6. How to use git commands
Use of any command options,--help
for example git stash --help
.
7. What is "git flow"?
Git Flow defines branching model a project release, the management has a scheduled release cycle of large-scale project provides a robust framework is a git operation process standards proposed by Vincent Driessen, solve when too many branches when, how effectively and quickly manage these branch.
8. What is GitHub flow?
GitHub flow, by definition, GitHub respected Workflow. (Do not understood as Workflow can be used on GitHub), basically, GitHub Flow is a master/feature
branch of the workflow brand name.
GitHub flow core strengths in process automation possibility that it brings, can do the inspection process other processes can not be achieved, and greatly simplifies the development team of physical labor, really play their own value.
9. What kind of branching strategy do you prefer?
Most projects are Git "Git flow". Only a few of these projects need this strategy, it is usually because the version of the software.
master/feature
Branching strategy easier to manage, especially when just getting started, if necessary, switch to the " git flow
" very easy.
10. git open command is used Zuosa
This is a separate command, it can be used as npm package.
11. When the files are added in other branches are still displayed in the working branch is not tracking or modification, how to reset branch
This is usually a result of switching branch to "work index" unclean.
No built-in way to git in to correct this. There is usually a by ensuring prompt " status
" indicator and run at each branch, such as changes to git status
the command and the like to avoid this situation. These habits will we find these problems as soon as possible, so that you can be on the new branch stash
or commit
the changes.
12. How to rename a branch?
git branch -m current-branch-name new-branch-name
复制代码
13. How cherry-pick
git cherry-pick [reference]
Remember, this is a re-application of command, so it will change submitted SHA.
14. If recovery from a branch (e.g. HEAD~3
), whether returns to HEAD
(such as the last update Recovery)
In this case, by running the git reset --hard HEAD~1
undo immediately submit the restore (that is HEAD
submitted).
15. When to use git pull
and git fetch
?
git pull
Download will be submitted to the current branch. Remember, git pull
in fact fetch
, and merge
command combinations.
git fetch
Get the latest quote from the remote.
A good analogy is a podcast player or e-mail client. You can retrieve the latest podcasts or e-mail ( fetch
), but in fact not yet in the local download podcasts or e-mail attachments ( pull
).
16. Why is sometimes necessary to use --force
to force commit the changes
rebase
Is a command can be re-submitted, it changes the SHA1
hash. If so, local commit history will no longer consistent with its remote branches.
When this happens, push
it will be rejected. Only when it is rejected, you should consider using git push --force
. Doing so will commit history with local history covering remote submission. So you can look back and think about it, think about why you want to use --force
.
17. You can use branching and merging multiple branches, then send the branch to master
do?
Of course, in most git work shed, a branch usually accumulate changes from a number of other branches, the branches will eventually be merged into the main branch.
18. It should be from a very old branch to make a rebase
right?
Unless there is no alternative.
Depending on your workflow, old branches can be merged into the main branch.
If you need a new branch, I prefer rebase
. It provides only change more clear historical record, and not from other branches or merge commit.
However, although always possible, but use rebase
may be a painful process, because each application must be re-submitted. This can cause multiple conflicts. If so, I usually use rebase --abort
and use merge
to once and for all conflicts.
19. The use of rebase -i
time, squash
and fixup
what's the difference
squash
And fixup combination of two submitted. squash
Suspend rebase
the process, allowing a message to adjust our submission. fixup
Automatic messages from the first submission.
20. In general, when using the master
re-establishment of functional branches, each submission will need to resolve the conflict?
Yes. Since the changes are submitted in each rebase
re-application period, so they must be resolved in case of conflict.
This means that it has been submitted prior to the submission of conflict, if not properly fix it, then the following submission of many conflicts may occur. To limit this, I often used rebase -i
to compress the submission history, to make it easier to use it.
If there is still a lot of conflict between the submission may be used merge
.
21. Prior to the merger with the master, it is necessary to do to update my branch
Depending on your workflow, old branches can be merged into the main branch. If your workflow uses only " fast-forward
" Merge, then it is necessary to update your branch prior to the merger.
Git fast forward submitted
Multiplayer co-development, using Git often see warning messages that contain the term: fast forward
this is what justice?
Is simply submit to a remote central warehouse code must be in chronological order.
For example, A
get the code from a central warehouse, the file f
has been modified. Then push
to the central warehouse.
B
In the A
prior got the central warehouse code in A push
also after a successful f
file has been modified. This time B
also run the push
command push code.
You receive a message similar to the following:
chenshu@sloop2:~/work/189/appengine$ git pushTo
ssh://[email protected]:29418/appengine.git ! [rejected]
master -> master (non-fast-forward)error: failed to push some refs to
'ssh://[email protected]:29418/appengine.git'To prevent you from losing
history, non-fast-forward updates were rejectedMerge the remote changes (e.g. 'git
pull') before pushing again. See the'Note about fast-forwards' section of 'git push --help' for details.
复制代码
Non-fast-forward way to remind you of the update was rejected, we need to start central warehouse pull
to the latest version, merge
then push
.
fast forward
To ensure that does not force covering other people's code, to ensure that the people collaborative development. Try not to use the non fast forward
method to submit code.
22. The need to use visualization tools do this GitKraken
I prefer to use the command git way, because it allows me to completely control and management changes, like using the command to improve my development process the same.
Of course, some visualization (such as management branch and view files difference) is always better in the GUI. I personally think that view them in the browser during the merge process is sufficient.
23. When the submission has been pushed, you can do a --amend
modified it?
Can git commit –amend
either modify the contents of the last commit, you can modify commit.
24. In doing iterative content, complete a small feature when you need to pull a pull request
later request, or have done this iteration of content in a pull pull request
request
Let's usual practice is that after the completion of an iteration of content in a pull pull request
. However, if you spend a long time on a task, to do the merge function may be beneficial. This prevents the branch dependence or outdated, so a finished drawing a request , or pull all done in a request , it depends on the type you going to change.
25. In the branch into master
before, you need to create a release
branch do?
It depends on your company's deployment process to a large extent. Creating release
a branch is useful for multiple branches of work grouped together and merge them into the main branch before the overall test.
Since the source branch to remain independent and not merge, therefore, have greater flexibility in the final merge.
26. How to obtain the number of submissions from the master? Let's say I do not want to perform the last commit, but once rebase
.
Assuming that master
the branch is our main branch, we do not want to submit to selectively extract from its history, which can cause conflict in the future.
We want merge
or rebase
all changes branches. Branch from the main branch outside the extraction choose to submit, it can be used git cherry-pick
.
27. How to configure the terminal colors git
By default, git is black and white.
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
复制代码
Once configured, there is color.
28. Is there a better alternative to the command git push -force?
In fact, no other way to substitute git push—force
. Nevertheless, if properly used merge
or rebase
updated branch, you do not need to use git push --force
.
Only when you run a command to change the local commit history, it should be used git push --force
.
29. When I git rebase -
choose drop
when and whether to delete the code associated with the submission?
Yes. To recover the code, the need reflog
of rebase
finding a state before.
30. How to automatically track a remote branch
Usually, when you checkout
when or create a branch, Git will automatically set up a branch track.
If not, the next time you can use the following command to update when: git push -u remote-name branch-name
.
Or you may use the following command set it explicitly:git branch --set-upstream-to = remote-name / branch-name
31. rebase
Update branch before the branch, it is a good habit?
I think that is the case, the reason is very simple, with git rebase -i
tissue compression or submit, first of all to provide more context during the update process.
32. Is there a way you can submit more split into submission (and fixup/squash
vice versa)?
You can rebase -i
use the exec
command to try and split the revision index changes. You can also be used git reset
to undo the most recent submission, and they change into work index, and then change their separation into new submission.
33. Is there a way to view the repaired submitted?
git log
View logs, find the corresponding change log, but this lookup can only see the file, rather than the contents of the file.
git blame file name
Record View modify this file, the default display the entire file, you can also, to check a few lines need to be modified via the parameter -L.
If you view the contents of previously submitted may be used git show commitId
.
34. rebase --skip role is what?
We know rebase
the process will produce first rebase
branch ( master
) backup, put (no branch) temporary branch. Then regional branch (branch) of each commit changes, in the form of patches, one re-applied to the main branch. This process is a cycle of patch application, the patch during the long conflict, the cycle will stop and wait for manually resolve the conflict. This conflict refers to the conflict between the version and patch after a merger.
git rebase --skip
Command, you can skip a certain patch (on the existence of a solution to the conflict, it has been included in this round of patches content, it would be invalid patch, you need to skip), this command with caution.
35. How do I delete a remote branch?
You can use: git push origin:branch-name-to-remove
or use the -d
options: g it push -d origin someother -branch-2
to remove the remote branch.
To delete a local reference to the remote branch, you can run: git remote prune origin
.
36. checkout
and reset
what is the difference
Both of these commands can be used to undo the changes. checkout
It may be more robust, because it not only allows undo the current changes, but also allows to undo a set of changes by retrieving an older version of the file.
By default, reset
more suitable for the work to change the state of the index changes. Therefore, it is actually only deal with the current changes.
git checkout -- file
; Undo changes to the work area; this time the command is the latest storage node (add and commit) as a reference, covering the work area corresponding to the file file
; this command is to change the work area.
git reset HEAD -- file
; Emptied add
on command submitted to the staging area file
to modify the file (Ustage); this command changes the staging area only and does not alter the work area, which means that in the absence of any other operations, the actual document workspace with no change before running the command
37. In the normal workflow in which commands should be avoided
Some might destroy the contents of history, such as:
git push origin master -f (千万不要这样做)
git revert
git cherry-pick (changes from master)
复制代码
Under normal operating procedures, to avoid direct use git merge, as it is normally built into the process by pulling the request (pull requests) a.
38. If I have a branch (B) points to another branch (A), and I have another branch (C), which requires (A) and (B) and mast branch code, how a process to update ( C)?
It depends on several things:
If A
and B
can be incorporated into master
just be A
and B
incorporated into master
, and then use master
an update C
.
If you A
and B
can not be incorporated into master
, it can simply be B
incorporated into C
, since B
already contains A
changes.
In the extreme case, it may be A
, B
and master
incorporated into C
the. However, to avoid conflicts, combined order may be important.
39. What are you using alias
I used some git aliases as follows:
alias.unstage reset HEAD --
alias.append commit --amend --no-edit
alias.wip commit -m "WIP"
alias.logo log --oneline
alias.lola log --graph --oneline --decorate --all
复制代码
40. What are the little-known git command?
git bisect
Find the code is present in the bug
life-saving tools. Although only a few times, but its accuracy is impressive, it saves a lot of time.
git archive
It is a good tool for packaging a set of changes. This helps with third parties or mico-deployment
work-sharing.
git reflog
It may be well known, but it is worth mentioning, because it provides an error in the "undo" command in a good way.
41. Can you recommend some books about Git do
I recommend reading at least Pro Git first three chapters. Over the years, each seen again, more or less have a harvest.
<Git Study Guide> also good.
Link: https: //juejin.im/post/5dba2249f265da4cef190484