Git cheat sheetRussell Bateman |
$ git branch
$ git checkout -b branch-name
$ git checkout branch-name
$ git checkout -b branch-name
If you do work in a (new) branch, create new files or make changes in files, but fail to add/commit those files, then when you switch (or checkout) another branch, git will automatically merge those files to that branch.
This is not often what you really want git to do. However, ...
...while this appears frustrating, any other strategy would result in the loss of your work on that (new) branch. You must at very least, add, then commit to that branch's local git repository (else how can you think git could keep it?)
$ git checkout master $ git merge branch-name
$ git branch -d branch-name
$ git branch * master $ git checkout -b generic-patient-ids Switched to branch 'generic-patient-ids' $ git branch * generic-patient-ids master —do some work in the new branch, be certain to add and commit it $ git checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. $ git branch * master generic-patient-ids $ git merge generic-patient-ids Updating ee385b2..7d87195 Fast-forward1 pom.xml | 3 ++- src/main/java/com/acme/OrganizationUtilities.java | 2 +- src/main/java/com/acme/Author.java | 10 +++++----- . . . src/test/resources/allergies.xml | 16 ++++++++-------- src/test/resources/immunizations.xml | 4 ++-- 46 files changed, 359 insertions(+), 152 deletions(-) create mode 100644 src/main/java/com/acme/pojos/Id.java create mode 100644 src/test/java/com/acme/PatientRoleTest.java $ git status On branch master Your branch is ahead of 'origin/master' by 11 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean $ git branch -d generic-patient-ids Deleted branch generic-patient-ids (was 5b24e08).
1 Fast-forward means it's a blissful day because there are no conflicts you must resolve between your new code and something that changed in master while you were off working on that new code.
$ vim .gitignore
$ git rm -r --cached filename
$ git commit --amend -m "(Fix screwed-up commit message)"
$ git add filename $ git commit --amend --no-edit
$ git checkout filename
$ git restore .
$ git log --name-status (record the commit hash)
$ git restore --source commit-hash filename
$ git restore filename
$ git reset --hard origin/master