Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ You need to know 12 Git High Command     - Linux System Getting Started Tutorial: permission to permanently modify the USB device in Linux (Linux)

- Ubuntu System Log Configuration / var / log / messages (Linux)

- How do I use Linux development environment (Linux)

- ORA-12154 TNS could not resolve the specified identifier (Database)

- Ubuntu 14.10 / 14.04 / 12.04 How to install Kodi 14.0 RC3 (Linux)

- How to Install lightweight Budgie desktop on Ubuntu 14.04 (v8) (Linux)

- Linux use glibc2 library and crypt () function to generate the user password (Programming)

- Let your PHP 7 faster (GCC PGO) (Linux)

- Some of the bibliographic management tools to good use on linux (Linux)

- Linux kernel network subsystem analysis (Programming)

- Vmstat command Linux Performance Monitoring (Linux)

- Java proxy use and proxy principle (Programming)

- Security: Unix operating system intrusion tracking Strikes Back (Linux)

- Linux User Rights Study Notes (Linux)

- printf PHP string operations () built-in function usage (Programming)

- The ORA-01113 error is handled with BBED without archiving (Database)

- Windows SmartGit installation (Linux)

- Linux installed xdotool simulate keystrokes and mouse movements (Linux)

- How to deploy Python Web application: Heroku deployment process complete records (Server)

- Linux systems for entry-learning - Install Go language in Linux (Linux)

 
         
  You need to know 12 Git High Command
     
  Add Date : 2018-11-21      
         
         
         
  As we all know, Git distributed version control is already a leader in the field, around Git formed a complete ecosystem. Learn Git, first of all learn the basic workflow with Git. A powerful tool, compared to other traditional SVN version control systems, Git is designed for distributed version control and students. Frequently used commands when using Git has pull, commit, push, etc., seemingly very simple. Sometimes, however, the situation you will encounter merge conflicts, Git will then flagged conflict, you need to manually resolve. Sometimes you accidentally code submitted to the wrong branch, and then pushed to the remote repository. Other times, you need to switch to a different branch, but Git will not let you do that, because there are unsaved changes. If you need to submit to another branch of the code patch how to do it? This article will introduce 12 advanced Git command, the rational use of these commands can greatly enhance the efficiency of use Git.


1. Use rebase instead of merge to pull upstream modification

Branch merger will be recorded as a merge commit, this approach makes sense. For example, it can in this way to identify a new feature has been incorporated into the release branch. However, when employees work in multiple teams to a project and using conventional git pull to synchronize branch, will be submitted to the timeline to submit the merger unnecessary pollution. Better approach is to use a feature branch git rebase to rebase to master branch:

$ Git checkout feature
$ Git rebase master
Doing so will move the entire feature branch to start master branch, it will merge all new commits on the branch master. However, compared to the use of merge commit, the change by creating a new group will be submitted to rewrite the history of the project in the original branch for each submission. The main change for the better group that you will get a much cleaner project history. In addition, there are variations on the base of the trap of some discussion.


2. After the execution of git rebase to resolve merge conflicts

As the power comes greater responsibility for the same. When executed git rebase, you may encounter merge conflicts. Merge Conflicts represents two to commit changes to the same row of the same file, Git does not know which one to modify the application. This will result in an error message such as the following:

Git will provide you with three options to fix the conflicting submitted (fa39187):

You can run git rebase -abort completely cancel rebase. Doing so will cancel rebase modify, and branch back into the state of implementation of git rebase before.

You can run git rebase -skip completely ignore the submission. Thus, a problem to submit changes introduced will not be added to the history.

You can use the same criteria merge conflicts steps to resolve the conflict.


3. Save the modified temporary

At work, some things will always be in a messy state. If you then need to switch to a different branch of the how to do it? Git does not allow you to do so, because there are unsaved changes. Frank to say that you do not want to submit semi-finished products go up, come back to modify. Way to solve this problem is to use git stash command. Stash receives the current state of the working directory (for example, to modify the track file changes and staging areas, etc.), and save it to the stack of unfinished changes, so you can then later be modified at any time. You can scratch your work with the following command:

$ Git stash
Saved working directory and index state WIP on feature: 3fc175f fix race condition
HEAD is now at 3fc175f fix race condition
Now, the working directory is clean:

$ Git status
# On branch feature
nothing to commit, working directory clean
Then you can safely switch the branch do something else. But do not worry, this is still in the staging of submission:

$ Git stash list
stash @ {0}: WIP on feature: 3fc175f fix race condition
Later, after returning to feature branch, you can retrieve all the staged changes:

$ Git stash pop
On branch feature
Changes not staged for commit:
  (Use "git add ..." to update what will be committed)

     modified: index.html
Dropped refs / stash @ {0} (ac2321cc3a33ba712b8e50c99a99d3c20da9d6b8)
About scratch, there are several other options are available as follows:

$ Git stash save "describe it" # give the stash a name
$ Git stash clear # delete a stashed commit
$ Git stash save --keep-index # stash only unstaged files

4. clone a particular remote branch

If you want to clone a particular branch from a remote repository in how to do it? Normally you would use git clone, but to do so all the other branches will be cloned down. A convenient way is to use the git remote add:

$ Git init
$ Git remote add -t -f origin
$ Git checkout

5. Submit to cherry-pick the remote into your branch

Moreover, if you just want to submit a specific remote repository into their own branch in how to do it? You can use git cherry-pick to select a given SHA values ​​submitted, and then merged into the current branch:

$ Git cherry-pick

6. Application from unrelated local patch repository

If you need another unrelated local repository submit patches to the current Warehouse how to do it? The answer is the following command:

. $ Git --git-dir = / git format-patch -k -1 --stdout | git am -3 -k

7. Ignore the track file changes

If you and your colleagues manipulated the same branch, it is likely to require frequent execution git merge or git rebase. However, doing so may be reset a number of related and environmental profile, so after each merger need to be modified. In contrast, you can tell Git permanently by following commands do not control a local file:

$ Git update-index --assume-unchanged

8. run once every X seconds git pull

Often, the reason is that you merge conflicts are working local repository no longer reflects the current state of the remote repository. This is why every morning to first perform a git pull sake. In addition, you can also script (or use GNU Screen) called once every X seconds git pull in the background:

$ Screen
$ For ((i = 1; i <= 10000; i + = 1)); do sleep X && git pull; done

9. subdirectory separated into new warehouse

Sometimes you may need to Git repository in a particular directory into a new warehouse. This can be achieved git filter-branch:

$ Git filter-branch --prune-empty --subdirectory-filter master
# Filter the master branch to your directory and remove empty commits
Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
Ref 'refs / heads / master' was rewritten
Now, the warehouse will contain all the files in the specified subdirectory. All files will be deleted before though, but they still exist in the Git history. Now a new local repository can be pushed to the remote.


10. Cleanup

Sometimes, Git will prompt "untracked working tree files" will be "overwritten by checkout". The reasons for this are many. But generally speaking, we can use the following command to keep the tree clean and work to prevent this from happening:

$ Git clean -f # remove untracked files
$ Git clean -fd # remove untracked files / directories
$ Git clean -nfd # list all files / directories that would be removed

11. Project files into tar package, and excludes .git directory

Sometimes, you need to provide a copy of the project to GitHub repository was unable to access external members. The easiest way is to use tar or zip package to all project files. However, if you are not careful, the hidden .git directory will be included in the tar file, which causes the file size larger; at the same time, if the documents inside and receivers Git repository confused, it would be more headache a. Easy rule of thumb is do automatically excluded from tar file out .git directory:

$ Tar cJf .tar.xz / --exclude-vcs

12. Find Modifier

Finally, if the chaotic situation, you will want to find out who is responsible. If the production server goes down, then find the culprit is relatively easy to do: just follow git blame. This command will display each line of the file author, submit hash on the line will be modified to identify, but also to see the submission time stamp:

$ Git blame
Of course, Git command is very much, in addition to the 12 most important commands introduced above, I believe you InfoQ readers in the daily course of their work have their own preference and useful commands, it may be in the form of comments to share with other readers.
     
         
         
         
  More:      
 
- Linux shell script to adjust the Task Scheduler (Linux)
- With screenfetch linux logo and basic hardware information display with cool Linux logo (Linux)
- Linux compiler installation Redis (Database)
- Realization of Linux operating system illegal IP censorship (Linux)
- CentOS7 + Redis Live Installation and Configuration (Linux)
- Ubuntu system cp: omitting directory problem (Linux)
- FreeBSD install Gnome 3 Desktop (Linux)
- Android HTTP request with Get Information (Programming)
- Ubuntu 14.10 Apache installation and configuration (Server)
- Linux system Iptables Firewall User Manual (Linux)
- Nginx Module Development - get user ip (Server)
- To install PostgreSQL 9.4 (Database)
- Postgres-X2 deployment steps (Database)
- After installing Ubuntu 15.04, to do a few things (Linux)
- Grub2 Boots the openSUSE installation image (Linux)
- CentOS 7 RHEL 7 to reset the root password (Linux)
- MySQL 5.6 Open full query log (Database)
- Linux virtual machine how to access the Internet in a virtual machine when using NAT mode (Linux)
- Repair after installing Ubuntu no boot device error (Linux)
- Linux network monitoring strategy (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.