A program to help me roll back to older versions of my code

Go To Last Post
53 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello I recently did a bunch of changes on my code that I have regretted and I think it is about time for me to start using a... "versioning program"? Is that how it is called? Anyway I didn't know how to search for it so I thought I should ask here. What should I look for? Any programs you are using in particuolar?

This topic has a solution.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

Last Edited: Sun. Jan 24, 2021 - 08:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

tellSlater wrote:
Hello I recently did a bunch of changes on my code that I have regretted

Did you do those changes in MPLABX or in Atmel Studio. If you did those on MPLABX you will find every individual file save has been stored in the local history. Sadly Atmel Studio (nor Visual Studio for that matter) has this feature.

 

As far as Repository based Version Control Systems go then GIT https://git-scm.com/ is the current favourite of many developers. It thoroughly deserves it's position as favourite due to excellent performance and features.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

tellSlater wrote:
"versioning program"? Is that how it is called?

"Software Version Control System" - SVCS

 

aka "Revision Control", etc.

 

As  N.Winterbottom  said, Git seems to be the current favourite; eg, with GitHub

SVN is another option; I find it simpler,  especially for "single developer" projects - which sounds like your case.

 

In both cases, there is a Tortoise client - which lets you do revision control stuff right in the Windows Explorer

 

 

https://tortoisesvn.net/

 

https://tortoisegit.org/

 

If you search the forum for "Git" and "SVN" you will find plenty of previous discussions & recommendations...

 

If you're bored with "Compiler Wars", you could try asking "which is best - Git or SVN?" ...

 

surprise

 

EDIT

 

Other Windows clients are available;

 

Other operating systems are available.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jan 21, 2021 - 09:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I work on Atmel Studio. :/ Thanks a lot, I will try it

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:

Sadly Atmel Studio (nor Visual Studio for that matter) has this feature.

 

Visual Studio does have revision control as well as many other features through Team Foundation Server which may be run as a local server or using the Cloud version. Visual Studio itself however does not offer revision control.

 

 

There are Git clients for Visual Studio however.

 

Wayne

Wayne

East London
South Africa

 

  • No, I am not an Electronics Engineer, just a 54 year old hobbyist/enthusiast
  • Yes, I am using Proteus to learn more about circuit design and electronics
  • No, I do not own a licensed copy of Proteus, I am evaluating it legitimately
  • No, I do not believe in software or intellectual property piracy or theft
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There was recently a long thread about trying to get Git integrated into Atmel Studio:

 

https://www.avrfreaks.net/forum/how-interface-github-atmel-studio7

 

Of course, the fact that it's not integrated into the IDE does not mean that you can't version-control Atmel Microchip Studio projects - you can always do it from the Windows explorer (or command line, if you prefer).

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tellSlater wrote:

I work on Atmel Studio. :/ Thanks a lot, I will try it

 

That's fine. You use Git to control the contents of a 'repository', effectively a folder containing your files.

 

You use Atmel Studio to edit them still.

 

In your case, if you decide to revert a set of changes - you do this with Git, then next time you open Atmel Studio, all your changes will have been reverted. In fact, you can even do this with Atmel Studio and the files open - you'll just get a dialog box saying the files have been changed.

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

For years I used SVN and was a great advocate for it. For anyone in Windows I would recommend TortoiseSVN but, because of things like Github these days, Git is so pervasive and there is such wide support available for any aspect of it's use (either in connection to Github or standalone) that I would probably recommend the latter.

 

git kind of encourages command line use to get the very best out of it - most of the 100 plus commands have 20-50 options so you can get very precise control over what you want to do. But there are GUI integrated helpers for it too if you want to use it that.

 

To start maintaining your files with revision control (which includes the ability to "wind back") is literally almost as simple as installing it and then giving a "git init" command in the directory where you already have project filles.

 

Here is a very simplistic example:

D:\git_example>type test.c
#include <avr/io.h>

int main(void) {
    DDRB = 0xFF;
    while(1) {
        PORTB ^= 0xFF;
    }
}

This is the work of art I have created so far. I now want to version manage it so:

D:\git_example>git init
Initialized empty Git repository in D:/git_example/.git/

D:\git_example>

As that output alludes to the thing that turns "a collection of files" into "a collection of files that are being maintained by Git" is simply that a new directory is added at the top level of of the directory structure called ".git" (on some operating systems things that start with a "." remain 'hidden' so it might not be immediately obvious anything changed). From now on Git will use that to maintain a status of all the files you want to control in that subdirectory. However at this stage nothing is "watched"/"controlled" because while there are files in this directory (well one) we want git to keep an eye on there might be some files (like the temporary ones that are generated when you build) that you would not want it to look after. So we need to tell it which files to track. At the moment if I use the status command (something you will use a lot!) to see what the current status is I would be told:

D:\git_example>git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        test.c

nothing added to commit but untracked files present (use "git add" to track)

D:\git_example>

This tells us a few things. Firstly that we are "on branch master". I won't get into branches in this simple explanation but just note that when you first do "git init" the branch name chosen for you first ever branch is "master". Now because of controversy about the use of the terms "master"/"slave" there is a movement to not use "master" any more (even though in this context it has nothing to do with master/slave but simply means "this is the main copy of everything"). But the fact is that Github for example have  switched to using "main" rather than "master" as the usual first branch in a repository so if I was to try and store this stuff in Github right now (even though nothing says you have to use Github if you don't want to) there could be a problem with this being "master" and Github assuming "main".

 

Anyway enough political correctness crap - the point is that this git command (oh and did I say that all git commands tend to take the form of "git <command> [optional parameters]") to show status has told us that we have a repository, there is an active branch called "master", git can "see" one file in this directory but so far it has not been told to track it. So let's do that:

D:\git_example>git add test.c

D:\git_example>git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   test.c


D:\git_example>

The file we are going to track has now moved from untracked to what's known as a "staging area". It's ready to be tracked but we haven't yet said "take a snapshot of the staged files and store it for posterity" just yet (this is because I might still want to make a few more changes before I finally do that). But let's assume we're happy with the file contents as they are and we want to take a copy at this stage. So we want to tell git to commit a copy of (all staged) things as they are right now to memory". The command is "git commit". So doing that:

D:\git_example>git commit -m "first copy of files"
[master (root-commit) 30202ce] first copy of files
 1 file changed, 8 insertions(+)
 create mode 100644 test.c

D:\git_example>

Now usually you would actually have git configured so you can just type "git commit" and that causes it to start an editor (which can be your "favourite editor" if you configure it right - I use Notepad++) and then you type in a short description of what you have fixed or changed. But for now I used the simple command line option "-m" to say not only "commit these files" but "commit these files and set the message in the history to be "first copy of files"). Now when I use status I can see:

D:\git_example>git status
On branch master
nothing to commit, working tree clean

D:\git_example>

So nothing is untracked and nothing is currently staged. Everything is "clean" and up to date. So here's a new command to play with. Suppose we want to see the history of what has happened to the files so far we can look at the log (another thing you will do a lot!). So:

D:\git_example>git log
commit 30202ced6aafbbb19c7aa76baf9de8a377294348
Author: Cliff Lawson <cliff.lawson@someplace.com>
Date:   Thu Jan 21 09:49:24 2021 +0000

    first copy of files

D:\git_example>

So Git has remembered some details about that commit I just made. For example it has remembered who did it (this gets useful if/when multiple people start to work on the files and you want to know who did what). It also remembered exactly when I did it. When you start using git for real and remember "the code was working last Tuesday" then you are going to be able to look at the log, spot where Tuesday's version was and get access to that if you need to. Note the very long number that git has given this change. It is called an "SHA" and these are vital to the way git works. SHAs are "hashes". That is a unique number that identifies all that changed. If I did want to go back to last Thursday and say "I'd like that one please" the way you are going to do it is using the SHA as an identity number. But you are probably thinking "no way on earth am I going to type 40 hex digits", while you could actually copy it from this output to use it the fact is that git is smart enough that when you give an SHA you only need to give as many of the first digits in the number that will be unique from any other SHA in the repository. So I could probably get away with using just "30202c" or something like that to refer to the change.

 

Anyway so far we've just committed one set of files, git only really comes into its own when you now start to modify some files so let's see that in action. I realise that in my little LED flasher program that I have written so far I haven't put in the delay that is going to be needed to be able to actually see the LED  flashes. So I edit the file so it is:

D:\git_example>type test.c
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
    DDRB = 0xFF;
    while(1) {
        PORTB ^= 0xFF;
        _delay_ms(1);
    }
}

So I've made some edits to that (with two obvious bugs that I will come to in a minute) but wait a moment, what did I actually change anyway? Now you could play "spot the ball" where you look at this post and the two copies of the code I have in it so far and switch your eyes back and forth to try and work out what has changed. But you don't have to do that because this is the first point at which git starts to pay back the exorbitant entrance fee you paid to be able to use it (joke, it's open software, completely free!). I can get it to show me what I just changed:

D:\git_example>git diff test.c
diff --git a/test.c b/test.c
index a98d0e1..0027415 100644
--- a/test.c
+++ b/test.c
@@ -1,8 +1,10 @@
 #include <avr/io.h>
+#include <util/delay.h>

 int main(void) {
     DDRB = 0xFF;
     while(1) {
         PORTB ^= 0xFF;
+        _delay_ms(1);
     }
 }

D:\git_example>

Now command line "diff" is not to everyone's taste and you can have this invoke all kinds of fancy difference programs (configured to your favourite). For example I have mine set to a program called "meld" so if instead of "git diff test.c" I had typed "git difftool test.c" I would see:

where the two lines I added are clearly shown. But let's stick with command line diff for now - although the output is "unusual" it gets across pretty much the same message.

 

So let's say I'm finished for today. The code is compiling OK (I'll ignore warnings for now) and I want to take a "security copy" of the day's work just so I have something I can get back to if I need to. So:

D:\git_example>git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   test.c

no changes added to commit (use "git add" and/or "git commit -a")

D:\git_example>git add test.c

D:\git_example>git commit -m "Added a delay so LED can be seen"
[master 8e4e02d] Added a delay so LED can be seen
 1 file changed, 2 insertions(+)

D:\git_example>git log
commit 8e4e02d6f8d1e2725b33f2976e030a200332b87b
Author: Cliff Lawson <cliff.lawson@someplace.com>
Date:   Thu Jan 21 10:13:22 2021 +0000

    Added a delay so LED can be seen

commit 30202ced6aafbbb19c7aa76baf9de8a377294348
Author: Cliff Lawson <cliff.lawson@someplace.com>
Date:   Thu Jan 21 09:49:24 2021 +0000

    first copy of files

D:\git_example>

Hopefully all of that is obvious. I had worked on the file so a git status showed me (by listing "modified" in red) that at least one of my files had changes but this was not staged/commited yet. You may have noticed that git often helpfully gives a hint as to what you might want to do next in a lot of the output it produces so it even told me I probably want to do a "git add". So I took their advice and did that. That moved the changes I had from local edits to the staging area ready to be committed. Then I just immediately did the git commit to save the staged files in the history of the repository. When I then did a git log it now shows that the history has two committed snapshots of the files. 

 

I'm not going to do this (we'll see!) but suppose I now had the thought "I'm not sure about using _delay_ms(), perhaps I should use a timer instead?" which means "I really would like to just revert things to where they were before I started to add the delay stuff. Well I could do that. To "pick something out" the git command is "git checkout" and you may have already guessed that if the thing I want to checkout is something in the git log then to identify which entry it is I want I could use the SHA (or at least the first few digits).

 

In fact (because I know I can recover from this! ;-) let's actually see that in action:

D:\git_example>git checkout 30202
Note: checking out '30202'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 30202ce... first copy of files

D:\git_example>type test.c
#include <avr/io.h>

int main(void) {
    DDRB = 0xFF;
    while(1) {
        PORTB ^= 0xFF;
    }
}

D:\git_example>

I'm not going to attempt to try and explain "detached head" in this simple intro but the key point here is that my copy of test.c is now the first version, not the one with the delay stuff added. I've managed to revert it to before recent changes. However for now I want to get back on track and the quickest way for me to do that is:

D:\git_example>git checkout master
Previous HEAD position was 30202ce... first copy of files
Switched to branch 'master'

D:\git_example>

Notice how this time the thing I checked out was not a specific SHA but simply the name of the branch "master". This is one thing that makes git powerful (many commands can take many different kinds of reference) but also a thing that can be a bit confusing for beginners at first. But basically what I was saying here was "just get me back onto the master branch and make sure it is up to date". So I will be back on "master" and at the 8e4e02 label - that copy that had the start of my delay stuff.

 

Now I said there were a couple of bugs in my AVR code. One is that <util/delay.h> should not be used without defining an F_CPU value so I need to correct that, the other is that 1ms is never going to work. If you flash an LED at 1ms it flashes so fast it will just look like it's on all the time. So I need to make some edits:

D:\git_example>git diff
diff --git a/test.c b/test.c
index 0027415..ed1d949 100644
--- a/test.c
+++ b/test.c
@@ -1,3 +1,4 @@
+#define F_CPU 8000000UL
 #include <avr/io.h>
 #include <util/delay.h>

@@ -5,6 +6,6 @@ int main(void) {
     DDRB = 0xFF;
     while(1) {
         PORTB ^= 0xFF;
-        _delay_ms(1);
+        _delay_ms(100);
     }
 }

D:\git_example>

I made the edits. This time I used "git diff" rather than specifically "git diff test.c". As I only have changes in one file the result is actually the same but if I was tracking 10 files and edited 7 of them the output of just "git diff" would show me the back to back changes in all 7 edited files while "git diff test.c" would only show me the change to that one file. 

 

Just to round things off I just need to put these recent changes to bed. You probably guessed (and "git status" would remind you if you forgot) that what I need to do is "git add <file>" to make git aware of the changes I want to snapshot (commit) and I'll then need a "git commit" to get that added to the history. So:

D:\git_example>git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   test.c

no changes added to commit (use "git add" and/or "git commit -a")

D:\git_example>git add test.c

D:\git_example>git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   test.c

D:\git_example>git commit -m "Fixed some problems with delay"
[master 24f0d9f] Fixed some problems with delay
 1 file changed, 2 insertions(+), 1 deletion(-)

D:\git_example>git log
commit 24f0d9f59c492d77e7568a8b6c611fbbe115f9f7
Author: Cliff Lawson <cliff.lawson@someplace.com>
Date:   Thu Jan 21 10:34:51 2021 +0000

    Fixed some problems with delay

commit 8e4e02d6f8d1e2725b33f2976e030a200332b87b
Author: Cliff Lawson <cliff.lawson@someplace.com>
Date:   Thu Jan 21 10:13:22 2021 +0000

    Added a delay so LED can be seen

commit 30202ced6aafbbb19c7aa76baf9de8a377294348
Author: Cliff Lawson <cliff.lawson@someplace.com>
Date:   Thu Jan 21 09:49:24 2021 +0000

    first copy of files

D:\git_example>

And I'll leave it at that for a "first introduction". Git is actually enormous. Those of us who've used it for 10 or 15 years still find new stuff almost daily. There are endless books written, endless internet articles, about 50% of the questions on stackoverflow.com are about git (this is where I usually find my answer if I want to know or be reminded how to do something).

 

The user manual itself is surprisingly approachable: https://git-scm.com/docs/user-ma...

 

As I said before Github has really encouraged widespread use of git and they have their own documentation: https://docs.github.com/en (some of that though is about how git is specifically used with github).

 

Talking of github, I know people were outraged when Microsoft bought it but that guarantees stability. What Github will do for you is provide a "safe place for a copy of your git history". If I had a github account (I do) I could just create a new repository in my account to track my "LED flasher" project then (being careful of "master"/"main" mismatch problems) I could "push" a copy of what I have done so far into the LED flasher repository copy on my git hub account. In fact why don't I do that...

 

Note that I am setting this "Public". That means you will be able to go to github.com on the internet and see my project as it develops. But if it was "just for me" I could have chosen private. I ticked boxes for Readme (every piece of software you ever write should have some documentation to go with it!) and I chose to have it create a suitable ".gitignore". I won't get too bogged down in that but it's basically a file to say to Git "when you are monitoring all the files in my project directory and tempted to tell me about any that are "untracked" don't bother with certain types of files like *.o, *.a, *.elf, *.lss" and so on as I'm not interested in keeping the history or copies of those".

 

When I click "Create repository" it starts out looking like:

 

As it says that is at: https://github.com/wrightflyer/L... (it really is - you can go there now and see it).

 

So far it only contains the auto-generated .gitignore and Readme.md files (the contents of which are shown below so that file is a good way for you to let others know what your project is all about if you are publicly sharing it). You might note that the 1 branch it has created so far is "master" (not Github's recent choice of "main"). I have my github configure so it continues to follow the old fashioned behaviour of creating "mater".

 

Of course I have my files on disk that I've been tracking and this repository on github has been created but so far nothing links them as some of the excellent documentation on Github will tell you the way to "import existing files" into a repository is explained at:

 

https://docs.github.com/en/githu...

 

In all of that the real "magic" is when I go to my local repository and do the:

git remote add origin  <REMOTE_URL>

using the detail I can pick up from:

 

so that becomes:

D:\git_example>git remote add origin https://github.com/wrightflyer/LED-Flasher.git

D:\git_example>

Now if I follow the online docs for Github it tells me to try (in my case replacing "main" with master) the following:

D:\git_example>git push origin master
Fatal: HttpRequestException encountered.
Username for 'https://github.com': wrightflyer
Password for 'https://wrightflyer@github.com':
To https://github.com/wrightflyer/LED-Flasher.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/wrightflyer/LED-Flasher.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

D:\git_example>

The situation we're currently in is that my local repository has one set of files (well "test.c" in fact) and the newly created repository on Github.com is different (it has .gitignore and Readme.md). So I need to merge the two. I do that by first pulling what github.com has to my local copy:

D:\git_example>git pull --rebase
warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/wrightflyer/LED-Flasher
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

D:\git_example>

The command "git pull" basically means "give me the changes I haven't got over here",  the additional "--rebase" means "then put my changes on top of that". But it didn't work - however git is being helpful again. It's reminding me of something else I need to do to link the two. So I need to give the command:

D:\git_example>git branch --set-upstream-to=origin/master master
Branch master set up to track remote branch master from origin.

D:\git_example>

Which is saying the thing I call "master" locally should be linked to the thing on the server/website called "master". The website copy is "origin" - kind of "the central copy" - though everyone using this repo in Git will have a copy and they are all effectively equal - "distributed" is the word. It's just we're going to treat the copy held by the server as the "central" one.

 

Now I can complete the "git pull" I just attempted before (and this time it works):

D:\git_example>git pull --rebase
First, rewinding head to replay your work on top of it...
Applying: first copy of files
Applying: Added a delay so LED can be seen
Applying: Fixed some problems with delay

D:\git_example>dir
 Volume in drive D is DATA
 Volume Serial Number is 1CF4-86D6

 Directory of D:\git_example

21/01/2021  11:49    <DIR>          .
21/01/2021  11:49    <DIR>          ..
21/01/2021  11:49               482 .gitignore
21/01/2021  11:49                58 README.md
21/01/2021  11:49               184 test.c
               3 File(s)            724 bytes

So what's happened here is that it went and got what the server/web had (readme.md and .gitignore and their history), then in turn it applied the 3 changes I had built up locally on top of that. So in total I now have all the files together.

 

If we now look at git log:

D:\git_example>git log
commit e12dfe5419ff3ebf23902ae88432a2d4850ca39b
Author: Cliff Lawson <cliff.lawson@some-corporation.com>
Date:   Thu Jan 21 10:34:51 2021 +0000

    Fixed some problems with delay

commit e35869c46aa06d1c9a713fb8dea23d63c8649c5b
Author: Cliff Lawson <cliff.lawson@some-corporation.com>
Date:   Thu Jan 21 10:13:22 2021 +0000

    Added a delay so LED can be seen

commit 7ba3cb23a20ed6a84bcc643cfd0d82ad477cdf3f
Author: Cliff Lawson <cliff.lawson@some-corporation.com>
Date:   Thu Jan 21 09:49:24 2021 +0000

    first copy of files

commit 155a07853142cd3fb750a62282171ef8cd627095
Author: Cliff Lawson <wrightflyer@users.noreply.github.com>
Date:   Thu Jan 21 10:50:52 2021 +0000

    Initial commit

D:\git_example>

So the two histories have been combined. "155a0" is where the website created .gitignore and Readme.md and it gave it a default commit message of "Initial commit". Then "7ba3", "e358" and "12d" are the work I had done locally placed "on top".

 

When you think about it, my copy of the repo (with 4 commits) is now in advance of what the server/web have. In fact you can see that over there:

 

It only knows about one commit (the one when the repo was created and .gitignore and readme.md were added). So I need either now, or at some point in the future to push the changes I have locally (the other 3 commits) back to the origin/master so it's up to date. In theory if I wait someone else might be working on the same repo and get in before me so if I don't act now I might find my locally held changes haven't seen some other work someone else has done (in reality on my own projects I have two computer in two locations and either one might be the last one to have brought origin/master up to date). So I will push the changes I have now to make sure we're all in step...

D:\git_example>git push origin master
Fatal: HttpRequestException encountered.
Username for 'https://github.com': wrightflyer
Password for 'https://wrightflyer@github.com':
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 968 bytes | 0 bytes/s, done.
Total 9 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/wrightflyer/LED-Flasher.git
   155a078..e12dfe5  master -> master

D:\git_example>

The command was "git push" (let them know what I have) but to be very specific I am saying "push to origin" and "send what I currently hold on branch master".

 

The other end shows all the signs of having accepted what I sent. I can see that if I revisit the website:

So that is just a more "visual" view of what I see if I type "git log" locally. It shows the SHAs but only shows the first few characters (because you'd seldom need to quote more than are shown here to identify a specific change).

 

If I click:

 

(which was my first commit) I can see the entire repository as it looked at that stage. If I had clicked on:

 

it would have shown all that happened in that commit:

 

 

So 8 lines of a new file called test.c were created. Clicking through to see the details of a later change I might see:

 

or the other commit I made (where I fixed a couple of bugs):

 

So while I can do all this stuff using my local repository and command line tools like "git status", "git log", "git diff" or even visual tools like "Meld" using "git difftool" there's an argument for saying this is a whole lot more easy to use and is far more visual with github.

 

It does other things like tracking all the work you do on Github:

The very dark green entry there is:

 

 

So I pushed 10(!) commits on that single day. Gulp.

 

Oh did I say you can do other stuff in Github like a Wiki for a specific project where you can keep a record of what you have been doing or hold design notes and that kind of thing:

 

https://github.com/wrightflyer/S...

 

Anyway, enough already, like I say it can take decades to learn all that is available but this maybe gives a flavour of the basics and how to get started. (then google stackoverflow when you come up against something you'd like to do but don't know how to!)

 

Last Edited: Wed. Feb 24, 2021 - 09:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been trying to make things work with git since I did not see your comment later. Yep I am "single developer" as you said. I couldn't find a nice GUI where all the versions are there to see. Is that something SVN offers?

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
git kind of encourages command line use to get the very best out of it ... But there are GUI integrated helpers for it too if you want to use it that.

 

eg, Tortoise Git - mentioned earlier.

 

Note that you can use Tortoise Git with GitHub (as you can also use the standard command-line)

 

GitHub repositories don't have to be publicly visible 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tellSlater wrote:
I couldn't find a nice GUI where all the versions are there to see

Not sure what you mean by that?

 

tellSlater wrote:
Is that something SVN offers?

SVN - like Git - is the underlying system; not a GUI.

 

Various GUIs do offer various ways to view your repository

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice explanation Cliff!!

 

I too had/have been thinking of some sort of SVN for my projects, and that explanation Might be a tutorial of sorts for me to take a try at it again.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow things have gotten pretty wild here! Thanks everyone, imma take my time and read through these

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For personal use, where you not sharing this with others, but just want to have local control, then tortioseSVN works well for me in windows.

It's simple to use and does not need an internet connection to work.

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've used CVS, SVN and GIT. They have all seemed complicated to me.

If access to your (main) repository is across a network then GIT is better because locally you don't checkout files, you clone the repository.  So if you want to switch between branches a lot git is much faster.  If you want to commit when the network is down only git can help you. 

If you want to understand git a little more this article about git internals may be of interest.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:
Sadly Atmel Studio (nor Visual Studio for that matter) has this feature.
fyi, functionality in Windows 10.

Incremental backup: File History | Top 35 free apps for Windows 10 | Computerworld

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MattRW wrote:
... clone the repository.
in GitLab for Xcode

Clone to Apple Xcode | Repository | GitLab

 

edit : GitLab can integrate with Visual Studio though Visual Studio Code is preferred.

A VS Code extension for GitLab: GitLab Workflow | GitLab

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Thu. Jan 21, 2021 - 08:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Re: clawson #8:

 

OMG! All that is why I still use RCS = simple check-in, check-out!

 

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mha11 wrote:
OMG! All that is why I still use RCS = simple check-in, check-out!

 

Nop, I used that >20 years ago, not going back. Git is not so bad with Github; it is sure nice to be able to check something in and push it to Github, then login to a remote R-Pi and do a git pull (then build) and upload while being able to roll back to a previous version without needing that network uplink. When my internet is spotty, I can still work, checking in as many versions as I like, then when it is up again; I can push those changes to Github; I learned some difficult to shake bad habits with SVN  (when not always able to check-in).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the old days we used a folder called "revisions" and zip your project folder, call it r01 or r02 ect. Drop it in the folder. Would zip a revision before/after feature completion, and code changes. Simple yet effective.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All that is why I still use RCS = simple check-in, check-out!

I was going to point out that RCS is very simple and easy to understand, and is probably sufficient for the OP's needs (save old versions, be able to revert to them.)

But these days git/github offer so much more...

 

I found https://blog.udacity.com/2015/06... to be a useful intro to version control in general, and git specifically.

 

 

Last Edited: Tue. Jan 26, 2021 - 03:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

Now that looks interesting - Does anyone know whether this is like Apple's Time Machine or more like the old but most excellent VAX/VMS file versioning ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
But these days git/github offer so much more...

yup...

clawson wrote:
most of the 100 plus commands have 20-50 options so you can get very precise control over what you want to do

 

The power of Git is that for almost anything you can ever think you might need someone has been there before you and has add a command or an option to do just that.

 

The only real challenges are (a) finding out what that command/option actually is (probably the very reason God invented StackOverflow!) and (b) in normal use determining from 100 * 50 command/options what are the 10 basic commands you only ever really need.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:

Now that looks interesting - Does anyone know whether this is like Apple's Time Machine or more like the old but most excellent VAX/VMS file versioning ?

 

If that kind of thing interests you then have a look at https://www.ajcsoft.com/active-b...

 

I've been in contact with the (UK based) developer about it, and to see if it works alongside how I use Dropbox, and it's on my 'buy and install' list.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
probably the very reason God invented StackOverflow!
Lol, I've often claimed that git is proof Satan exists and writes software.  As the lengthy intro to the tool alludes, git is a nightmare of complexity.  In keeping with Linux culture, proponents seem committed to doing things the hard way.

 

Years ago during my first exposure to git the tool kept complaining that as a result of my commit I now have a "detached head".  I never discovered what that really means; in fact I've avoided learning just so I can complain about it.  Revision control is an ancient concept and it really isn't inherently complicated.

 

Still, git is ubiquitous.  In this industry you must hold your nose and learn to use it.  Period.

C: i = "told you so";

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

cpluscon wrote:
"detached head"

 

Ha

 

https://stackoverflow.com/questions/10228760/fix-a-git-detached-head#10229202

 

I liked how Mercurial SCM does things; it worked for me but has various issues; there are trade-offs due to design decisions, no matter what. I am still on a slow Git learning curve and will probably be for the rest of my life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The git manual is a surprisingly good /easy read and explains things like detached head well. (but never once goes as far as mentioning "Nearly Headless Sir Nicholas"! ;-)

Last Edited: Wed. Jan 27, 2021 - 08:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for a very detailed intro clawson; I've been needing to get more acquainted with git and that is a good start to begin messing with it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12oclocker wrote:
In the old days we used a folder called "revisions" and zip your project folder, call it r01 or r02 ect.

I've done it that way.

 

You don't even need to Zip; just copy the folder tree - drag & drop in the File Explorer, or xcopy at the command line.

The advantage of a copy (rather than Zip) is that it's far easier to do a file compare between revisions.

 

Simple yet effective.

Certainly simple, but less effective that a proper SVCS; eg, it give you no history.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cpluscon wrote:
Linux culture ... doing things the hard way

 

laugh laugh laugh laugh laugh laugh 

 

So true!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've just spent the last few days learning Conan/Artifactory. If I thought Git was complex I may have found something to challenge that!

 

https://conan.io/

https://jfrog.com/artifactory/

 

It's a bit like Git but is for version managing release binaries rather than sources.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
The advantage of a copy (rather than Zip) is that it's far easier to do a file compare between revisions.

Archive Types | Beyond Compare Technical Support

...

Once you have expanded the archive by double-clicking on it, the files within will be compared. 

...

File comparison software and directory comparison software - UltraCompare

[mid-page]

 

Compressed archive compare

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

Archive Types | Beyond Compare Technical Support

...

Once you have expanded the archive by double-clicking on it, the files within will be compared. 

...

Exactly - which is a step you don't need to do if you don't Zip it in the first place!

 

File comparison software and directory comparison software - UltraCompare

[mid-page]

 

Compressed archive compare

assuming you have a copy of UltraCompare - which is not free.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Brian Fairchild wrote:

If that kind of thing interests you then have a look at https://www.ajcsoft.com/active-b...'ve been in contact with the (UK based) developer about it, and to see if it works alongside how I use Dropbox, and it's on my 'buy and install' list.

 

So, I've been playing with the eval version of this and will probably be buying it.

 

How does it work? It runs in the background monitoring a list of directories you specify matching, and excluding, file extensions that you specify. On each write to disk any changes are written to an archive file per source file, again in a specified directory.

 

Need to go back a few steps? Easy, right click on the file in explorer and up pops a window...

 

 

You can your own descriptions to a file, or select a couple of them and run the inbuilt diff...

 

 

I like it because it's automatic. Every time I hit compile in CV all changed files get written to disk and now they are automatically versioned.

 

There's a whole load of other options I still need to explore that deal with automatically pruning the archive to keep the size down. Plus loads of other stuff.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds interesting.

 

One of the things a SVCS does is to manage changes to a group of files - can it do that?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I've been through a few git tutorials and videos - one question I have is this - let's say you want to go back to a moment in time.  using "git checkout sha .".  This presumably wipes out anything you have in the working directory, so you can really only do that if you don't have any changes pending or you've committed those changes, right?  Essentially the repo becomes the gold standard of the files that have been added to it.  Then you can return to your latest set of files with "git checkout master .", right?

 

It looks like you can also use the git checkout command without the trailing dot to change where the head is, off of the master and possibly onto an older commit.  Why would one ever want to do that?  If they want to create a branch at certain point?

 

Thanks,

 

Alan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alan, git won't let you checkout until things are "clean" so if you have been working on stuff but then want to step back you just tidy up then git add the stuff you've been working on. After git add the stuff is "staged" then to add it to the history you git commit. Now you git log to find the place in the history you want to go to and git checkout that_sha. When done you then just got checkout master to get to the top of your local history where you started. If that old sha is something you want to work on (rather than just view/build) then at the "git checkout that_sha" you might actually "git checkout - b new_branch_name that_sha" and that will create a new branch where the old version can be developed further. At any time (after add/commit to clean up) you can checkout master to work there or checkout new_branch_name to continue working on that old version, perhaps fixing something.
.
PS the best way to learn git is to use it. Just create a new repo and work on a project and try stuff out. Throw it all away if something bad happens (or ask for guidance). I have an expert I contact if I ever dig myself into a hole.

Last Edited: Thu. Feb 11, 2021 - 09:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if you have work in progress and want to check out something else:

$ git checkout devel
<edit files but don't commit>
$ git stash
$ git checkout master
<look but don't touch>
$ git checkout develop
$ git stash pop
<continue to edit files>

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MattRW - do the git checkout master or git checkout develop lines actually change any working directory files?  Do they need a dot after them?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

git checkout will change the files.  (It's spooky to me how silently that occurs.)  If I have a file loaded in an editor the editor often tells me "file has changed."

 

I don't know anything special about the dots; that usually refers to the current directory.  So it might only checkout files in the current directory: if you're in a subdir' it will not update parent dir' files, I guess.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

alank2 wrote:
It looks like you can also use the git checkout command without the trailing dot
Sorry but what "trailing dot" are you talking about?

 

Anyway, following on from #8 here is a little sequence that kind of illustrates what I described in #38:

 

 

1) git status shows that I have a local edit in file test.c

 

2) git diff on that file shows what has changed (basically I changed DDR/PORT from B to D). To prepare to store my changes I git add so the file is "staged"

 

3) git log lets me see the history of everything. --oneline to get a one line summary of each entry is a very useful option when all you are interested in are the title lines of each commit and their SHA numbers

 

4) This is where I first try to "roll back". I spotted e35869c as the version in the history as the one I'd like to see so I try to git checkout but it fails. git recognises that while I have done the git add to put my recent change in the staging area I haven't committed the change so it has not been recorded in the history of the branch so if I do check something out now that change to test.c will still be lost. As always git has some helpful advice advising me either to commit the change (my idea in #38) or stash it (Matt in #39).

 

5) So I follow the advice and git commit the change. Usually I would give no parameter in which case git would start my favourite editor so I could type in War and Peace about the reasons behind the change etc. but when doing a screen dump you can't easily show the editing stuff so I simply went for a one line summary with -m and a summary message.

 

6) This git status simply shows how the respoistory history now looks. Unlike (3) above there is now the new 557b01d entry added where my "current work" has been stored

 

7) I used git branch -a next simply to show that at present I'm on master.

 

8) Then comes the git checkout where I roll back. It's going to checkout the old e35869c version and I'm saying that as it does so it should create a new branch where that might be worked on called "roll_back"

 

9) Now when I look at the file content it has miraculously changed to that old version (but it's the one that had faults - no F_CPU and 1ms is too short). I could now work on this, change things, git add and git commit but these commits would create a diverged history from master but it lets me develop a new version of the code based on that old starting point

 

10) However on this occasion I just git checkout master to switch back to where I started

 

11) and now when I type the file it's that one with the F_CPU, 100ms, D instead of B

 

I guess what I should also show is (now that I have two main working branches: master and roll_back):

 

 

So this time:

 

1) git branch now reveals the presence of both "master" and "rollback" held locally with master shown as being the current branch

 

2) so to flip over I can just git checkout roll_back. You can't see my edits but I then used my editor (nano) to make some changes to test.c in this branch

 

3) I used git diff to show what I changed. This is a "special version" of the code ("roll_back" may not have been the most appropriate name for this branch!) where I have set F_CPU to be 2MHz and used an 80ms delay (100ms elsewhere).

 

4) Then I just used git status as I often do to query "where are we exactly?". It confirms that I am working on the "roll_back" branch and I currently have a file with edits that either needs add/commit or to be discarded. I chose the former

 

5) So I follow the normal pattern of git add to stage the change and git commit to add the staged commit to the roll_back branch

 

6) Now the git log here is the history of this current branch so it matches master as far as e35869c but has then diverged with my special changes on top (1416dea).

 

7) I can now flip between the two branches at any time. Here I git checkout master to go back to my main development and git log show the history on this branch where it's right up to date with that B->D change but there's no sign of the special 2MHz/80ms work.

 

Last Edited: Fri. Feb 12, 2021 - 09:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am confused about what the dot means exactly.  It seems to be a wildcard for "all files" like * is.  If one does a checkout with a filename, like "git checkout 1234 file.txt", then it doesn't move the head, but just "gits" the file from that commit.  Does that mean that "git checkout 1234 ." gets all the files from commit 1234, but leaves the head at master?  It seems to if I do a git status after that.

 

C:\0git\1>git init
Initialized empty Git repository in C:/0git/1/.git/

C:\0git\1>git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

C:\0git\1>copy con test.txt
line1
^Z
        1 file(s) copied.

C:\0git\1>git add test.txt

C:\0git\1>git commit -m "initial"
[master (root-commit) fdb19c5] initial
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

C:\0git\1>copy con test.txt
line1
Overwrite test.txt? (Yes/No/All): y
line2
^Z
        1 file(s) copied.

C:\0git\1>git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")

C:\0git\1>git add test.txt

C:\0git\1>git commit -m "second"
[master 622adba] second
 1 file changed, 1 insertion(+)

C:\0git\1>git status
On branch master
nothing to commit, working tree clean

C:\0git\1>git log --oneline
622adba (HEAD -> master) second
fdb19c5 initial

<< now let's try to checkout with no . >>'

C:\0git\1>git checkout fdb19c5
Note: switching to 'fdb19c5'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at fdb19c5 initial

C:\0git\1>type test.txt
line1

<<okay, we are back to the first file>>

C:\0git\1>git checkout master
Previous HEAD position was fdb19c5 initial
Switched to branch 'master'

C:\0git\1>type test.txt
line1
line2

<<okay, we are back to the second file>>

C:\0git\1>git status
On branch master
nothing to commit, working tree clean

<all is well again, I am surprised because it seems like previously doing a git checkout master did not fix the detached state>>

C:\0git\1>git checkout fdb19c5 .
Updated 1 path from 30da65d

C:\0git\1>type test.txt
line1

<<back to the first file again>>

C:\0git\1>git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   test.txt

<<but we did not switch the head, it thinks test.txt is a change from "master" and needs to be added/committed>>

C:\0git\1>git log --oneline
622adba (HEAD -> master) second
fdb19c5 initial

C:\0git\1>type test.txt
line1

C:\0git\1>git checkout master
Already on 'master'
M       test.txt

<<I was already on master, but with the file checked out of the first commit, but it did NOT change the file to master's version>>'

C:\0git\1>type test.txt
line1


C:\0git\1>notepad test.txt
<<I added hello! to the file>>

C:\0git\1>
C:\0git\1>git checkout master
Already on 'master'
M       test.txt

<<still shows it modified>>

C:\0git\1>type test.txt
line1

hello!

C:\0git\1>git add test.txt

<<it is now staged>>

C:\0git\1>git checkout master
Already on 'master'
M       test.txt

<<I should have typed the file to see if it still had hello here, but didn't>>'

C:\0git\1>git checkout fdb19c5 .
Updated 1 path from 30da65d

C:\0git\1>type test.txt
line1

<<we are back to the first file>>

C:\0git\1>git checkout master
Already on 'master'
M       test.txt

<<still shows as modified>>

C:\0git\1>type test.txt
line1

<<still the original file>>

C:\0git\1>del test.txt

<<delete the file>>

C:\0git\1>git checkout master
Already on 'master'
D       test.txt

C:\0git\1>type test.txt
The system cannot find the file specified.

<<I did a checkout master, but it did not restore the file>>
<<is this because it is staged??>>

C:\0git\1>git checkout master .
Updated 1 path from 0eb5f3e

<<this forces it to restore the file>>

C:\0git\1>type test.txt
line1
line2

<<but no hello, is this because I didn't commit it with hello!'

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am confused about what the dot means exactly.  It seems to be a wildcard for "all files" like * is. 

No "." has just one meaning "current directory"

 

Normally you would not need to use it in a git command.

 

As for:

<< now let's try to checkout with no . >>'

C:\0git\1>git checkout fdb19c5
Note: switching to 'fdb19c5'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at fdb19c5 initial

The fact is that if you just "git checkout SHA" then you are bound to be in a detached head state. This is the thing that I said previously was confusing for some. You can actually "git checkout <all sorts of things>". It can be a branch name, a filename, a wildcard for multiple filenames, an SHA. For a filename/wildcard (which will include "." meaning "everything in this directory") then it just says "get the version of this most recently committed". If you checkout a branch name it actually means "make that branch, complete with its history the current working environment". But if you just "git checkout SHA" you are saying - take me direct to this item (which might be some point in the history of any branch) but you are not saying "and switch on to the branch". It's just saying "give the whole set of files as they were on that day". But suppose you now edit something, add and commit - where is it going to go? You are not actually on a branch any more - you are in a "detached head" - a kind of "snapshot" but it has no history you can now add on to. That's why if the the thing you are about to checkout is an SHA you probably want to add a "-b new_branch_name" to the checkout to say "got and get it and then create a branch that has all the history up to that SHA and is ready for new add/commits to be done to add more SHA history to it".

alank2 wrote:

<all is well again, I am surprised because it seems like previously doing a git checkout master did not fix the detached state>>

No this is exactly what you would expect - you went off for a quick nosey at some old version but as soon as you "git checkout master" it gets you back to where you were before you went off to the detached head.

alank2 wrote:

C:\0git\1>git checkout fdb19c5 .
Updated 1 path from 30da65d

C:\0git\1>type test.txt
line1

<<back to the first file again>>

What you've actually said here is go back in history and get me an old version but because you used "." rather than a specific filename it has not only brought (to master) the old version of a single file but "." meant "old version of all the files in this directory"
alank2 wrote:

<<but we did not switch the head, it thinks test.txt is a change from "master" and needs to be added/committed>>

Yeah so you just said "pick up all files as they were back at fdb and dump them into this working directory (HEAD@master)" so because that old version differs from HEAD it's bound to say "modified".
alank2 wrote:

C:\0git\1>git checkout master
Already on 'master'
M       test.txt

<<I was already on master, but with the file checked out of the first commit, but it did NOT change the file to master's version>>'

That was kind of a "do nothing" command. It basically said "put me at exactly the place I'm already at" so nothing changed.

 

I think a lot can be learned from more frequent "git status" commands which will always tell you where you are and what the current state is.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Clawson for the explanations.  I'm getting more comfortable with git, my technique of zipping files is something I understand clearly, but it is certainly less convenient/capable.

 

Some testing shows that the "." does not mean just the current directory, but means all files.  git seems to accept * and *.* as well, and I'm going to just start using *.* because that matches my "all files" mindset a bit more.

 

Problems occur when you try to checkout if your current environment is not stable.  For example, if all is well I can "git checkout sha" or "git checkout master" and it will switch the files.  If there are any inconsistencies however in the working directly, just doing one of these commands doesn't necessarily bring back that environment that way it was.  It does seem to indicate that however with thiings like "M   filename" or "D   filename" so I guess that is your tip that it couldn't restore it the way you wanted.  This is when adding the *.* allows it to bring those files and possibly overwrite something.  I think I see why it is doing what it is doing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For you software nerds want to get your hands around GIT, I strongly recommend this article.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm reading this:

 

https://git-scm.com/book/en/v2/G...

>However, before you do that, note that if your working directory or staging area has uncommitted changes that conflict with the branch you’re checking out, Git won’t let you switch branches.

 

But it will.  In my test git directory if I change a file so that the working is different, it will still let me checkout:

 

C:\0git\2>git checkout c5cf
Note: switching to 'c5cf'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at c5cfb31 initial
M       test.1

C:\0git\2>git status
HEAD detached at c5cfb31
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.1

no changes added to commit (use "git add" and/or "git commit -a")

C:\0git\2>git checkout master
Previous HEAD position was c5cfb31 initial
Switched to branch 'master'
M       test.1

C:\0git\2>git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.1

no changes added to commit (use "git add" and/or "git commit -a")

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"git switch" seems to be a relatively recent addition: article (with rationale)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alan, but of course it'll let you checkout and lose stuff if you are not on an active branch but a detached head. It warned you of this when you became detached... "You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create,". That's the key point and the reason I used -b on checkout.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks clawson and MattRW!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Should *.componentinfo.xml be included in the repository or excluded?

Pages