![]() ![]() Vim-fugitive comes with its own fugitive-object. Keep in mind you can't edit the file because Vim is in Read-Only mode. You can get the SHA from git log or :Gclog. You can view any file from commit SHA or branch with :Gedit. Since it uses Vim's diff window, you can use vimdiff's ]c and [c to jump to next / previous change. Just pass the SHA you want to compare it with: :Gdiffsplit SHA_FROM_LONG_TIME_AGO Fugitive is smart enough to compare it with current file from that commit. You can perform a diff against any commits. :Gdiffsplitįugitive performs a vimdiff ( :h vimdiff) between a given file and a commit (default last commit) with :Gdiffsplit. If you're happy with your changes, run :Gwrite to stage it. Vim considers this as a change, so you can undo ( u) it if you change your mind. You can run :Gread and all yourchanges will be replaced with previous commit. Imagine that you are editing hello.c, then decided you want to revert this file back to its state in previous commit. :Gwrite does :Git add % and :Gread does :Git checkout %. :cnext " next item on quickfix window list Since :Gclog uses quickfix, normal quickfix navigation works: :cclose " close quickfix window You can pass options too, like: :Gclog -5 You can yank that with y +, then paste it with p or P. ![]() In the bottom of top window you see a SHA. You can't do this easily with original git log without workaround with git ls-tree and git show.ītw, here's a really cool trick with :Gclog. Pressing enter on the tree or parent SHA will take you to that window. ![]() It launches vim quickfix ( :h quickfix) window to display all your commit logs.įugitive shows tree, parent, and changed files in one convenient window. :Gclogįugitive's :Gclog is another useful feature. You can use Vim's :q or + c to close the blame window. Some shortcuts while you are on blame window: A " resize to show author You use this to find the last person responsible for that one buggy the code so you can yell at them (just kidding). :Git blame creates a git blame window inside vim. You can pass it any option that works with git command: To learn more, check out :h fugitive-staging-maps.įugitive's :Git wraps the git command. Some things you can do in :Gstatus window: / " to go between sections The latter will display an ugly "Press ENTER or type command to continue" outside vim window. When you run :Git without any argument, fugitive displays a summary window similar to :Gstatus.Ĭompare running :Gstatus with :!git status. I will cover some fugitive features below. Some of fugitive's feature makes some git activities even easier in Vim than doing it from terminal! You can use any plugin managers or use built-in pack to install it. Personally, I find using a dedicated tmux window/pane for git far more useful than :term.Īlthough vim does not have a internal git integration, fortunately for us, Tim Pope created vim-fugitive. You can run your git commands from terminal inside Vim. If git is installed in your system, you can use vim's bang ( :!) to execute any shell command. However, getting them to integrate with each other without plugins can be difficult, but not impossible. Vim and git are two equally great tools for two different things. In this article, I will discuss different ways to integrate vim with git. Generated by Hastie.An efficient vim-git workflow can boost productivity. The plugin can browse through the full repository history using :Agit or a single file history using :AgitFile Agit exampleĪgit example An mkaz conundrum. The Agit plugin displays repository information using a tabpage with multiple windows. Running :GitMessenger with a message displayed enters that message buffer allowing you to navigate back to older commits by typing o key. Activate the plugin using the :GitMessenger function to display the last commit message that modified the line. ![]() It will display the info in a Scratch window, or pop-up window if supporteed. The git-messenger plugin provides blame information on a per-line basis. Use :GitGutterStageHunk for selective staging of hunks.Use :GitGutterPreviewHunk to see hunk changes.Here are the top ones that I use frequently: The plugin also provides features beyond just visual cues. I setup the following two maps to navigate to next and previous hunks: The vim-gitgutter plugin also provides functions to navigate to changed hunks of code. View Git Changesįor viewing changes in a single-file, the gitgutter plugin adds visual cues for additions, subtractions, and modifications in the gutter left of the line numbers. However, there are still a few plugins that I use to make things easier. I prefer to do my gitting on the command-line, so I know exactly what is happening. There are a wide range of plugins and features to choose from, so your setup will depend on what you want to do. By default, Vim provides no integration with git, all functionality is provided by plugins. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |