5 Git Commands That Will Make Your Life Easier

Git is one of the most popular version control systems available, developed by Linux creator Linus Torvalds. It is used in both private systems and public websites for all kinds of development. No matter how experienced you are with Git, there are always opportunities to discover new things. Here are 5 examples that could change the way you work with this system.





1. Copying one file from another branch 

While working, it may happen that we delete or confuse a file, and we want to start from the beginning. It can also happen that when working with a certain branch, we realize that we need a file from another branch. This command will help us  get a file from another branch :





git checkout release_15.5.3 -- projects/test/src/feature-1.component.ts
      
      



To copy a specified file from a specific commit, use the command:





git checkout 2657d3e -- projects/test/src/feature-2.component.ts
      
      



Instead of a single file, we can also load the entire directory by specifying the path to it. Note that all paths are relative, so unless you are in the root of the repository, you must provide a relative path to your files.





2. Correction of the last commit message.

, , , , , .  , , .  :





git commit --amend
      
      



3. ().

, .  , :





git log --oneline --no-merges
      
      



, .





4. , .

, , ,     :





git log -S "Release"

commit dcae425d31b852a90593d999bc0e57db448b0c5a
Author: pavel-zlotarenchuk
Date:   Wed Mar 3 20:56:08 2021 +0300
      
      



5. .

, git,   .  git , (). , .  git checkout, , .  :





git clean -f -d
      
      



Git is a tool full of tricks to make our day-to-day work easier. The above list is by no means exhaustive or complete, these are only non-obvious but useful commands that I did not immediately discover and which have simplified my work many times.








All Articles