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 [2021/06/10 12:06] – [Squash Commits] tmccannanewdevs:git:commands [2024/03/25 16:35] (current) tmccanna
Line 1: Line 1:
 **New Developers Working Group** **New Developers Working Group**
-====== Git for Windows ====== +====== Useful Git Commands ======
- +
-===== Useful Commands ===== +
- +
-==== Git Commands ====+
  
   * ''git add myfile.txt'' --> stage a specific file   * ''git add myfile.txt'' --> stage a specific file
Line 14: Line 10:
   * ''git branch -D branchname'' --> delete a local branch (cannot delete a branch you currently have checked out, so switch to different branch first)   * ''git branch -D branchname'' --> delete a local branch (cannot delete a branch you currently have checked out, so switch to different branch first)
   * ''git checkout mybranch'' --> check out an existing branch   * ''git checkout mybranch'' --> check out an existing branch
-  * ''git checkout -b mynewbranch'' --> create a new branch and check it out at the same time +  * ''git checkout -b mynewbranch'' --> create a new branch based on your current branch and check it out at the same time 
-  * ''git checkout master'' --> switch to master branch+  * ''git checkout -b mynewbranch origin/main'' --> create a new branch based on your main branch rather than on your currently checked out branch 
 +  * ''git checkout main'' --> switch to main branch
   * ''git checkout -- docname.tt2'' --> resets a file you've changed back to its original state (like an undo / revert changes command)   * ''git checkout -- docname.tt2'' --> resets a file you've changed back to its original state (like an undo / revert changes command)
   * ''git cherry-pick <nowiki><hash></nowiki>'' --> apply a specific commit to your local branch   * ''git cherry-pick <nowiki><hash></nowiki>'' --> apply a specific commit to your local branch
Line 21: Line 18:
   * ''git cherry-pick -s <nowiki><first hash>^..<last hash></nowiki>'' --> apply a range of commits with your signoff to your local branch   * ''git cherry-pick -s <nowiki><first hash>^..<last hash></nowiki>'' --> apply a range of commits with your signoff to your local branch
   * ''git clean -d -i'' --> interactively delete untracked files you do not want   * ''git clean -d -i'' --> interactively delete untracked files you do not want
 +  * ''git clean -d -f'' --> delete untracked folders you do not want
   * ''git clone <nowiki>git://git.evergreen-ils.org/Evergreen.git</nowiki>'' --> clones a remote repository   * ''git clone <nowiki>git://git.evergreen-ils.org/Evergreen.git</nowiki>'' --> clones a remote repository
   * ''git commit'' --> invoke the default text editor to add a commit message   * ''git commit'' --> invoke the default text editor to add a commit message
   * ''git commit -m "my commit message"'' --> add brief commit message instead of opening the text editor to add a commit message   * ''git commit -m "my commit message"'' --> add brief commit message instead of opening the text editor to add a commit message
   * ''git commit <nowiki>--amend</nowiki>'' --> overwrite your last commit message   * ''git commit <nowiki>--amend</nowiki>'' --> overwrite your last commit message
 +  * ''git commit <nowiki>--amend --author='Jon Doe <example@example.com'</nowiki>'' --> amend commit author
   * ''git commit <nowiki>--amend --signoff</nowiki>'' --> view and amend your sign-off branch   * ''git commit <nowiki>--amend --signoff</nowiki>'' --> view and amend your sign-off branch
   * ''git commit <nowiki>--amend --signoff <hash></nowiki>'' --> view and amend your signoff for a specific commit on your sign-off branch   * ''git commit <nowiki>--amend --signoff <hash></nowiki>'' --> view and amend your signoff for a specific commit on your sign-off branch
Line 30: Line 29:
   * ''git config <nowiki>--global</nowiki> -l'' --> list all global configuration values   * ''git config <nowiki>--global</nowiki> -l'' --> list all global configuration values
   * ''git config <nowiki>--global</nowiki> keyname "value"'' --> create a global value   * ''git config <nowiki>--global</nowiki> keyname "value"'' --> create a global value
 +  * ''git config <nowiki>--global</nowiki> user.email "you@example.com"'' --> set your email address
 +  * ''git config <nowiki>--global</nowiki> user.name "FIRSTNAME LASTNAME"'' --> set your name
   * ''git fetch <nowiki>--all</nowiki>'' --> refresh your local cache from the remote branches (does not download new branches); equivalent to git remote update   * ''git fetch <nowiki>--all</nowiki>'' --> refresh your local cache from the remote branches (does not download new branches); equivalent to git remote update
 +  * ''git config -e'' --> show git configuration file
   * ''git fetch working'' --> fetches all new branches in the working directory   * ''git fetch working'' --> fetches all new branches in the working directory
   * ''git help'' --> access the built-in Git help documentation   * ''git help'' --> access the built-in Git help documentation
-  * ''git log <nowiki>--oneline</nowiki>'' --> list previous commits with their unique ids +  * ''git log'' --> lists most recent commits with details 
-  * ''git pull'' --> imports all updates from your default remote repo to your default local repo (usually, this is equivalent to 'git pull origin master'); pull is equivalent to doing a fetch followed by a merge +  * ''git log <nowiki>--name-only</nowiki'' --> lists first line only of most recent commits 
-  * ''git pull origin master'' --> import all updates from remote origin repo to local master repo +  * ''git log <nowiki>--oneline</nowiki>'' --> lists id plus first line only of most recent commits 
-  * ''git pull <nowiki>--rebase</nowiki> origin master'' --> rebases (rather than merges) new remote changes to your local repository+  * ''git pull'' --> imports all updates from your default remote repo to your default local repo (usually, this is equivalent to 'git pull origin main'); pull is equivalent to doing a fetch followed by a merge 
 +  * ''git pull origin main'' --> import all updates from remote origin repo to local main repo 
 +  * ''git pull <nowiki>--rebase</nowiki> origin main'' --> rebases (rather than merges) new remote changes to your local repository
   * ''git push working mybranchname'' --> push changes to the remote working directory   * ''git push working mybranchname'' --> push changes to the remote working directory
   * ''git push working <nowiki>--delete</nowiki> mybranchname'' --> delete a remote branch   * ''git push working <nowiki>--delete</nowiki> mybranchname'' --> delete a remote branch
 +  * ''git push working <nowiki>--force</nowiki> mybranchname'' --> forces an overwrite on your previous branch
   * ''git remote -v'' --> display remote directories   * ''git remote -v'' --> display remote directories
 +  * ''git remote show origin'' --> display remote directories
   * ''git remote update'' --> refresh your local cache from the remote branches (does not download new branches); equivalent to git fetch --all   * ''git remote update'' --> refresh your local cache from the remote branches (does not download new branches); equivalent to git fetch --all
   * ''git reset HEAD myfile.txt'' --> unstage a file that has already been staged   * ''git reset HEAD myfile.txt'' --> unstage a file that has already been staged
   * ''git reset <nowiki>--hard</nowiki>'' --> reset a current branch to its original state   * ''git reset <nowiki>--hard</nowiki>'' --> reset a current branch to its original state
   *    * 
-  * ''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 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 54: Line 61:
 ==== Rebase ==== ==== Rebase ====
  
-If your patch is behind current master, you'll need to rebase it.+If your patch is behind current main, you'll need to rebase it.
  
   - Open the git branch   - Open the git branch
-  - Type: git rebase origin/master --> rebases the current branch to master+  - Type: git rebase origin/main --> rebases the current branch to main (you can do this when you have your branch checked out and changes committed, but have not yet pushed it)
   - If there are merge conflict errors, type: git status   - If there are merge conflict errors, type: git status
   - Open the file with the problem in your preferred text editor (notepad++, vim, nano, etc.)   - Open the file with the problem in your preferred text editor (notepad++, vim, nano, etc.)
Line 68: Line 75:
 ==== Squash Commits ==== ==== Squash Commits ====
  
-If you are in your local working branch and you've pushed up two commits to the remote git repository, you can combine them:+If you have multiple commits in your local branch that you'd like to combine:
  
-  - Verify that you are in your local branch. +  - Use 'git log' to verify that the commits you want to combine are the most recent 
-  - Type: ''git rebase -i origin/master'' +  - Type ''git rebase -i HEAD~2'' (where is the number of commits you wish to combine)
-    * Alternatively if your branch is already built on current master, you can use: ''git rebase -i HEAD~4''   (where is the number of commits you wish to combine)    +
   - Your text editor will open and should show both of the commits, for example:   - Your text editor will open and should show both of the commits, for example:
     * pick 014e59c579 LP#1839359 Select element on login not accessible     * pick 014e59c579 LP#1839359 Select element on login not accessible
     * pick 9de92lsi9a LP#1839359 Select element on login not accessible     * pick 9de92lsi9a LP#1839359 Select element on login not accessible
-  - Change the word "pick" in the second line to "fixup" then save and close the file+  - Change the word "pick" in the second line to either "fixup" or "squash" then save and close the file
     * squash --> merges commits, then allows amendment of commit message     * squash --> merges commits, then allows amendment of commit message
     * fixup --> merges commits like squash does, but discards previous commit message     * fixup --> merges commits like squash does, but discards previous commit message
-  - Push the commit again, and force it to overwrite the previous commits: +  - Use "git commit --amend" if you need to edit the final commit message 
-    * ''git push --force working lp1839359_login_select:user/jdoe/lp1839359_login_select''+  - Push the changes up to your remote working directory as normal 
 +    * ''git push working user/jdoe/lp1839359_login_select'' 
 + 
 +If you've already pushed multiple commits up to your remote working git repository, you can still combine them: 
 + 
 +  - Follow the steps above, but when pushing, use "--force" 
 +    * ''git push <nowiki>--force</nowiki> working user/jdoe/lp1839359_login_select''
  
  
Line 118: Line 130:
   * '':w'' --> saves your work   * '':w'' --> saves your work
   * '':wq'' --> saves & closes   * '':wq'' --> saves & closes
 +  * '':set number'' --> turns on line numbers
 +  * ''?abc'' --> searches for occurrences of 'abc'
  
  
newdevs/git/commands.1623341186.txt.gz · Last modified: 2022/02/10 13:34 (external edit)

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.