Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ You need to know 12 Git High Command     - JIRA 3.6.2 Upgrade from older version to the new version 6.0.8 (Linux)

- netfilter- in kernel mode network packet operation (Linux)

- When Linux Detailed time zone and common function of time (Linux)

- Getting the Linux shell flow control statements (Programming)

- Ganglia Python plug-in the process of writing notes (Linux)

- Linux Variable content removal and replacement (Linux)

- Installation image conversion tool on your Ubuntu Converseen 0.8.1 (Linux)

- Programmer editor Vim (Linux)

- Linux scp remote file copy (Linux)

- Service Discovery: Zookeeper vs etcd vs Consul (Server)

- Java synchronization mechanism used in locking Thought (Programming)

- MongoDB3.0.x version of the user authorization profile (stand-alone environment) (Database)

- C language programming entry - Common operators (Programming)

- Java Learning: elegant string (Programming)

- Tsunami-udp accelerated network transmission (Linux)

- UNIX and class UNIX system security check notes (Linux)

- VMware Workstation virtual machine cloning (Linux)

- Repair Raspbian Encountered a section with no Package (Linux)

- LNMP summary of the issues common 502 Bad Gateway (Server)

- Unable to solve the official version of Android Studio online update problem (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:      
 
- Storm basic framework for analysis (Programming)
- Debian (Wheezy) were installed wxPython GUI development (Linux)
- Spring + MyBatis Multi data source switching (Database)
- Python uses multi-process pool (Programming)
- Red Hat Linux security settings document (Linux)
- Simple RPM package production (Linux)
- Ubuntu deployment Flask + UWSGI + Nginx Comments (Server)
- GitLab installation configuration notes (Linux)
- Java memory area and memory overflow exception (Programming)
- Some Linux networking tools you might not know (Linux)
- Do not enter password login ssh (Server)
- RedHat Linux 7 build yum source server (Server)
- Solve ORA-01012: not logged on (Database)
- To delete the directory and all specified files under the Mac (Linux)
- Expert advice: Do not use the computer security IE browser (Linux)
- CentOS 6.5 system installation Oracle11.2.0.4 basic steps (Database)
- CentOS5 installation Nodejs (Linux)
- Raspberry Pi configuration wireless hotspot (Linux)
- Stucts2 values on the page and how the attribute values corresponding to the Action (Programming)
- Linux kernel log --dmesg (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.