User Tools

Site Tools


newdevs:git:commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
newdevs:git:commands [2024/08/27 21:43] – Moving Vim and Bash to their own pages (from Git) slearynewdevs:git:commands [2025/04/04 13:28] (current) – [Useful Git Commands] tmccanna
Line 52: Line 52:
   * ''git reset <nowiki>--hard HEAD</nowiki>'' --> remove last commit   * ''git reset <nowiki>--hard HEAD</nowiki>'' --> remove last commit
   * ''git reset <nowiki>--hard HEAD~2</nowiki>'' --> remove last 2 commits (increment numeral as needed)   * ''git reset <nowiki>--hard HEAD~2</nowiki>'' --> remove last 2 commits (increment numeral as needed)
 +  * ''git revert <hash>'' --> remove a specific commit from a branch that you've applied multiple commits to
   * ''git rm badfile.txt'' --> delete a file (if the file is being tracked, be sure to add a commit message indicating the file has been deleted)   * ''git rm badfile.txt'' --> delete a file (if the file is being tracked, be sure to add a commit message indicating the file has been deleted)
   * ''git show <hash>'' --> display the commit text and differences of the specified commmit   * ''git show <hash>'' --> display the commit text and differences of the specified commmit
Line 59: Line 60:
   * ''gitk'' --> use this after committing changes but before pushing them to see what will be pushed   * ''gitk'' --> use this after committing changes but before pushing them to see what will be pushed
  
-==== Rebase ====+===== Rebase =====
  
 If your patch is behind current main, you'll need to rebase it. If your patch is behind current main, you'll need to rebase it.
Line 72: Line 73:
   - Type: git rebase <nowiki>--</nowiki>continue    - Type: git rebase <nowiki>--</nowiki>continue 
  
 +You can also use the interactive rebase mode to look at a series of commits:
 + 
 +  - Open the git branch
 +  - Type: ''git rebase -i origin/main''
 +  - (Optional but recommended) Save this pick list to a separate file, for recovery later if things go wrong
 +  - Choose what to do with each line using the commands listed in the comment block (pick, edit, drop, fixup, squash)
 +  - Save and close the "to do" file
 +  - Follow the prompts to complete each step you specified
 +
 +If you need to start over, just rebase again and paste in your original pick list.
  
-==== Squash Commits ====+===== Squash Commits =====
  
 If you have multiple commits in your local branch that you'd like to combine: If you have multiple commits in your local branch that you'd like to combine:
Line 94: Line 105:
     * ''git push <nowiki>--force</nowiki> working user/jdoe/lp1839359_login_select''     * ''git push <nowiki>--force</nowiki> working user/jdoe/lp1839359_login_select''
  
 +===== Aliases =====
 +
 +Shortens normal commands so you type less. You can add them one at a time from the command line:
 +
 +<code>
 +$ git config alias.co checkout
 +$ git config alias.cp cherry-pick
 +$ git config alias.br branch
 +$ git config alias.ci commit
 +$ git config alias.st status
 +</code>
 +
 +You can also edit ''~/.gitconfig'' to see your existing aliases.
 +
 +With the above aliases, you would check out main using:
 +
 +<code>git co origin main</code>
 +
 +==== Bash Aliases ====
 +
 +Mike Rylander suggests using bash aliases so you can skip typing ''git'':
  
 +<code>
 +# git-related contents of miker's ~/.bash_aliases
 +alias branch='git branch'
 +alias ci='git commit'
 +alias co='git checkout'
 +alias dif='git diff'
 +alias fetch='git fetch'
 +alias lg='git log --pretty=oneline'
 +alias pick='git cherry-pick'
 +alias pull='git pull'
 +alias push='git push'
 +alias stash='git stash'
 +alias status='git status'
 +alias wt='git worktree'
 +</code>
  
 +With these bash aliases in place, you would check out main using:
  
 +<code>co origin main</code>
newdevs/git/commands.1724809432.txt.gz · Last modified: 2024/08/27 21:43 by sleary

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.