From a753a0fee4c8a4250f9388cb66bb4f941a06a221 Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 19:10:42 +0800 Subject: [PATCH 001/223] =?UTF-8?q?[=E6=89=8B=E5=8A=A8=E9=80=89=E9=A2=98][?= =?UTF-8?q?tech]:=2020220520=20Add,=20Delete=20And=20Grant=20Sudo=20Privil?= =?UTF-8?q?eges=20To=20Users=20In=20Fedora=2036.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t Sudo Privileges To Users In Fedora 36.md | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md diff --git a/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md b/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md new file mode 100644 index 0000000000..e05f7007b7 --- /dev/null +++ b/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md @@ -0,0 +1,218 @@ +[#]: subject: "Add, Delete And Grant Sudo Privileges To Users In Fedora 36" +[#]: via: "https://ostechnix.com/add-delete-and-grant-sudo-privileges-to-users-in-fedora/" +[#]: author: "sk https://ostechnix.com/author/sk/" +[#]: collector: "lkxed" +[#]: translator: " " +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +Add, Delete And Grant Sudo Privileges To Users In Fedora 36 +====== +Create sudo user in Fedora. + +Using **sudo** program, we can elevate the ability of a normal user to run administrative tasks, without giving away the `root` user's password in Linux operating systems. This guide explains how to add, delete and grant sudo privileges to users in Fedora 36 desktop and server editions. + +I've divided this guide in three sections. The first section teaches you how to create a new user. In the second section, you'll learn how to give sudo access to the existing user. And in the last section, you will know how to remove sudo access from a user. I've also provided example commands in each section, so you can understand it better. + +First, we will start with giving sudo access to a new user. + +### 1. Create A New User In Fedora + +Login to your Fedora system as `root` user or `sudo` user. + +We can use either `useradd` or `adduser` commands to create users in Linux. + +For the purpose of this guide, I am going to create a new user called **"senthil"** using `adduser` command. + +To do so, I run the following command with `sudo` or `root` privilege: + +``` +$ sudo adduser senthil +``` + +Next, I am going to set a password to the newly created user "senthil" with `passwd` command: + +``` +$ sudo passwd senthil +``` + +![Create A New User In Fedora][1] + +We just created a normal user called "senthil". This user has not been given sudo access yet. So he can't perform any administrative tasks. + +You can verify if an user has sudo access or not like below. + +``` +$ sudo -l -U senthil +``` + +**Sample output:** + +``` +User senthil is not allowed to run sudo on fedora. +``` + +![Check If An User Has Sudo Access][2] + +As you can see, the user "senthil" is not yet allowed to run sudo. Let us go ahead and give him sudo access in the following steps. + +### 2. Grant Sudo Privileges To Users In Fedora + +To add a normal user to **sudoers** group, simply add him/her to the `wheel` group. + +For those wondering, the `wheel` is a special group in some Unix-like operating systems (E.g. RHEL based systems). All the members of `wheel` group are allowed to perform administrative tasks. Wheel group is similar to `sudo` group in Debian-based systems. + +We can add users to sudoers list in two ways. The first method is by using `chmod` command. + +#### 2.1. Add Users To Sudoers Using Usermod Command + +``` +Usermod +``` + +To grant sudo privileges to a user called "senthil", just add him to the `wheel` group using `usermod` command as shown below: + +``` +$ sudo usermod -aG wheel senthil +``` + +Here, `-aG` refers append to a supplementary group. In our case, it is `wheel` group. + +Verify if the user is in the sudoers list with command: + +``` +$ sudo -l -U senthil +``` + +If you output something like below, it means the user has been given sudo access and he can able to perform all administrative tasks. + +``` +Matching Defaults entries for senthil on fedora: + !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, + env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", + env_keep+="MAIL QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", + env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", + env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", + env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", + secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/var/lib/snapd/snap/bin + +User senthil may run the following commands on fedora: + (ALL) ALL +``` + +![Add A User To Sudoers Group Using Usermod Command][3] + +As you see in the above output, the user "Senthil" can run ALL commands on any host. + +#### 2.2. Add Users To Sudoers By Editing Sudoers Configuration File + +The another way to add users to sudoers list is by directly adding him/her to the sudoers configuration file. + +Edit sudoers configuration file using command: + +``` +$ sudo visudo +``` + +This will open `/etc/sudoers` file in your **Vi** editor or whatever you have in your `$PATH`. Scroll down until you find following entry: + +``` +root ALL=(ALL) ALL +``` + +Right after the above entry, add the following line: + +``` +senthil ALL=(ALL) ALL +``` + +![Add Users To Sudoers Group By Editing Sudoers Configuration File][4] + +Here, the line `ALL=(ALL) ALL` refers the user "senthil" can perform any commands on any host. Replace "senthil" with your own username. Save the file and close it. + +That's it. The user has been granted sudo access. + +#### 2.3. Verify Sudo Users + +Log out from the current session and log back in as the newly created sudo user. Alternatively, you can directly switch to the other user, without having to log out from the current session, using the following command: + +``` +$ sudo -i -u senthil +``` + +![Switch To New User In Fedora Linux][5] + +Now, verify if the user can able to perform any administrative task with `sudo` permission: + +``` +$ sudo dnf --refresh update +``` + +![Run Dnf Update Command With Sudo][6] + +Great! The user can able to run the `dnf update` command with sudo privilege. From now on, the user can perform all commands prefixed with sudo. + +### 3. Delete Sudo Access From A User + +Make sure you logged out of the user's session and log back in as `root` or some other sudo user. Because you can't delete the sudo access of the currently logged in user. + +We can remove sudo privileges from an user without having to entirely delete the user account. + +To do so, use `gpasswd` command to revoke sudo permissions from a user: + +``` +$ sudo gpasswd -d senthil wheel +``` + +**Sample output:** + +``` +Removing user senthil from group wheel +``` + +This will only remove sudo privilege of the given user. The user still exists in the system + +Verify if the sudo access has been removed using command: + +``` +$ sudo -l -U senthil +User senthil is not allowed to run sudo on fedora35. +``` + +![Delete Sudo Access From A User Using Gpasswd Command][7] + +#### 3.1. Permanently Delete User + +If you don't need the user any more, you can permanently remove the user from the system using `userdel` command like below. + +``` +$ sudo userdel -r senthil +``` + +The above command will delete the user "senthil" along with his  `home` directory and mail spool. + +### Conclusion + +This concludes how to add, delete and grant sudo privileges to users in Fedora 36 operating system. This method is same for other RPM-based systems as well. + +-------------------------------------------------------------------------------- + +via: https://ostechnix.com/add-delete-and-grant-sudo-privileges-to-users-in-fedora/ + +作者:[sk][a] +选题:[lkxed][b] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://ostechnix.com/author/sk/ +[b]: https://github.com/lkxed +[1]: https://ostechnix.com/wp-content/uploads/2022/05/Create-A-New-User-In-Fedora.png +[2]: https://ostechnix.com/wp-content/uploads/2022/05/Check-If-An-User-Has-Sudo-Access.png +[3]: https://ostechnix.com/wp-content/uploads/2022/05/Add-A-User-To-Sudoers-Group-Using-Usermod-Command.png +[4]: https://ostechnix.com/wp-content/uploads/2022/05/Add-Users-To-Sudoers-Group-By-Editing-Sudoers-Configuration-File.png +[5]: https://ostechnix.com/wp-content/uploads/2022/05/Switch-To-New-User-In-Fedora-Linux.png +[6]: https://ostechnix.com/wp-content/uploads/2022/05/Run-Dnf-Update-Command-With-Sudo.png +[7]: https://ostechnix.com/wp-content/uploads/2022/05/Delete-Sudo-Access-From-A-User-Using-Gpasswd-Command.png From b15b4ba3e56b92e490e7684630d9a7674a3cdc82 Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 19:15:42 +0800 Subject: [PATCH 002/223] =?UTF-8?q?[=E6=89=8B=E5=8A=A8=E9=80=89=E9=A2=98][?= =?UTF-8?q?tech]:=2020220520=20Add,=20Delete=20And=20Grant=20Sudo=20Privil?= =?UTF-8?q?eges=20To=20Users=20In=20Fedora=2036.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... Delete And Grant Sudo Privileges To Users In Fedora 36.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md b/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md index e05f7007b7..25c2a9af5b 100644 --- a/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md +++ b/sources/tech/20220520 Add, Delete And Grant Sudo Privileges To Users In Fedora 36.md @@ -9,9 +9,9 @@ Add, Delete And Grant Sudo Privileges To Users In Fedora 36 ====== -Create sudo user in Fedora. +Create sudo user in Fedora -Using **sudo** program, we can elevate the ability of a normal user to run administrative tasks, without giving away the `root` user's password in Linux operating systems. This guide explains how to add, delete and grant sudo privileges to users in Fedora 36 desktop and server editions. +Using `sudo` program, we can elevate the ability of a normal user to run administrative tasks, without giving away the `root` user's password in Linux operating systems. This guide explains how to add, delete and grant sudo privileges to users in Fedora 36 desktop and server editions. I've divided this guide in three sections. The first section teaches you how to create a new user. In the second section, you'll learn how to give sudo access to the existing user. And in the last section, you will know how to remove sudo access from a user. I've also provided example commands in each section, so you can understand it better. From d5fa15482bea82d5ef6dae5d78eb07a509400a80 Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 19:59:51 +0800 Subject: [PATCH 003/223] =?UTF-8?q?[=E6=89=8B=E5=8A=A8=E9=80=89=E9=A2=98][?= =?UTF-8?q?tech]:=2020220520=20A=20programmer-s=20guide=20to=20GNU=20C=20C?= =?UTF-8?q?ompiler.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... A programmer-s guide to GNU C Compiler.md | 272 ++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 sources/tech/20220520 A programmer-s guide to GNU C Compiler.md diff --git a/sources/tech/20220520 A programmer-s guide to GNU C Compiler.md b/sources/tech/20220520 A programmer-s guide to GNU C Compiler.md new file mode 100644 index 0000000000..00bfb93633 --- /dev/null +++ b/sources/tech/20220520 A programmer-s guide to GNU C Compiler.md @@ -0,0 +1,272 @@ +[#]: subject: "A programmer's guide to GNU C Compiler" +[#]: via: "https://opensource.com/article/22/5/gnu-c-compiler" +[#]: author: "Jayashree Huttanagoudar https://opensource.com/users/jayashree-huttanagoudar" +[#]: collector: "lkxed" +[#]: translator: " " +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +A programmer's guide to GNU C Compiler +====== +Get a behind-the-scenes look at the steps it takes to produce a binary file so that when something goes wrong, you know how to step through the process to resolve problems. + +![GitHub launches Open Source Friday][1] +Image by: Opensource.com + +C is a well-known programming language, popular with experienced and new programmers alike. Source code written in C uses standard English terms, so it's considered human-readable. However, computers only understand binary code. To convert code into machine language, you use a tool called a *compiler*. + +A very common compiler is GCC (GNU C Compiler). The compilation process involves several intermediate steps and adjacent tools. + +### Install GCC + +To confirm whether GCC is already installed on your system, use the `gcc` command: + +``` +$ gcc --version +``` + +If necessary, install GCC using your packaging manager. On Fedora-based systems, use `dnf` : + +``` +$ sudo dnf install gcc libgcc +``` + +On Debian-based systems, use `apt` : + +``` +$ sudo apt install build-essential +``` + +After installation, if you want to check where GCC is installed, then use: + +``` +$ whereis gcc +``` + +### Simple C program using GCC + +Here's a simple C program to demonstrate how to compile code using GCC. Open your favorite text editor and paste in this code: + +``` +// hellogcc.c +#include +  +int main() { +    printf("Hello, GCC!\n"); + return 0; +} +``` + +Save the file as `hellogcc.c` and then compile it: + +``` +$ ls +hellogcc.c + +$ gcc hellogcc.c + +$ ls -1 +a.out +hellogcc.c +``` + +As you can see, `a.out` is the default executable generated as a result of compilation. To see the output of your newly-compiled application, just run it as you would any local binary: + +``` +$ ./a.out +Hello, GCC! +``` + +### Name the output file + +The filename `a.out` isn't very descriptive, so if you want to give a specific name to your executable file, you can use the `-o` option: + +``` +$ gcc -o hellogcc hellogcc.c + +$ ls +a.out  hellogcc  hellogcc.c + +$ ./hellogcc +Hello, GCC! +``` + +This option is useful when developing a large application that needs to compile multiple C source files. + +### Intermediate steps in GCC compilation + +There are actually four steps to compiling, even though GCC performs them automatically in simple use-cases. + +1. Pre-Processing: The GNU C Preprocessor (cpp) parses the headers (#include statements), expands macros (#define statements), and generates an intermediate file such as `hellogcc.i` with expanded source code. +2. Compilation: During this stage, the compiler converts pre-processed source code into assembly code for a specific CPU architecture. The resulting assembly file is named with a `.s` extension, such as `hellogcc.s` in this example. +3. Assembly: The `as`sembler (as) converts the assembly code into machine code in an object file, such as `hellogcc.o`. +4. Linking: The linker (ld) links the object code with the library code to produce an executable file, such as `hellogcc`. + +When running GCC, use the `-v` option to see each step in detail. + +``` +$ gcc -v -o hellogcc hellogcc.c +``` + +![Compiler flowchart][2] + +Image by: + +(Jayashree Huttanagoudar, CC BY-SA 4.0) + +### Manually compile code + +It can be useful to experience each step of compilation because, under some circumstances, you don't need GCC to go through all the steps. + +First, delete the files generated by GCC in the current folder, except the source file. + +``` +$ rm a.out hellogcc.o + +$ ls +hellogcc.c +``` + +#### Pre-processor + +First, start the pre-processor, redirecting its output to `hellogcc.i` : + +``` +$ cpp hellogcc.c > hellogcc.i + +$ ls +hellogcc.c  hellogcc.i +``` + +Take a look at the output file and notice how the pre-processor has included the headers and expanded the macros. + +#### Compiler + +Now you can compile the code into assembly. Use the `-S` option to set GCC just to produce assembly code. + +``` +$ gcc -S hellogcc.i + +$ ls +hellogcc.c  hellogcc.i  hellogcc.s + +$ cat hellogcc.s +``` + +Take a look at the assembly code to see what's been generated. + +#### Assembly + +Use the assembly code you've just generated to create an object file: + +``` +$ as -o hellogcc.o hellogcc.s + +$ ls +hellogcc.c  hellogcc.i  hellogcc.o  hellogcc.s +``` + +#### Linking + +To produce an executable file, you must link the object file to the libraries it depends on. This isn't quite as easy as the previous steps, but it's educational: + +``` +$ ld -o hellogcc hellogcc.o +ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000 +ld: hellogcc.o: in function `main`: +hellogcc.c:(.text+0xa): undefined reference to `puts' +``` + +An error referencing an`undefined puts` occurs after the linker is done looking at the `libc.so` library. You must find suitable linker options to link the required libraries to resolve this. This is no small feat, and it's dependent on how your system is laid out. + +When linking, you must link code to core runtime (CRT) objects, a set of subroutines that help binary executables launch. The linker also needs to know where to find important system libraries, including libc and libgcc, notably within special start and end instructions. These instructions can be delimited by the `--start-group` and `--end-group` options or using paths to `crtbegin.o` and `crtend.o`. + +This example uses paths as they appear on a RHEL 8 install, so you may need to adapt the paths depending on your system. + +``` +$ ld -dynamic-linker \ +/lib64/ld-linux-x86-64.so.2 \ +-o hello \ +/usr/lib64/crt1.o /usr/lib64/crti.o \ +--start-group \ +-L/usr/lib/gcc/x86_64-redhat-linux/8 \ +-L/usr/lib64 -L/lib64 hello.o \ +-lgcc \ +--as-needed -lgcc_s \ +--no-as-needed -lc -lgcc \ +--end-group +/usr/lib64/crtn.o +``` + +The same linker procedure on Slackware uses a different set of paths, but you can see the similarity in the process: + +``` +$ ld -static -o hello \ +-L/usr/lib64/gcc/x86_64-slackware-linux/11.2.0/ \ +/usr/lib64/crt1.o /usr/lib64/crti.o \ +hello.o /usr/lib64/crtn.o \ +--start-group -lc -lgcc -lgcc_eh \ +--end-group +``` + +Now run the resulting executable: + +``` +$ ./hello +Hello, GCC! +``` + +### Some helpful utilities + +Below are a few utilities that help examine the file type, symbol table, and the libraries linked with the executable. + +Use the `file` utility to determine the type of file: + +``` +$ file hellogcc.c +hellogcc.c: C source, ASCII text + +$ file hellogcc.o +hellogcc.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped + +$ file hellogcc +hellogcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bb76b241d7d00871806e9fa5e814fee276d5bd1a, for GNU/Linux 3.2.0, not stripped +``` + +The use the `nm` utility to list symbol tables for object files: + +``` +$ nm hellogcc.o +0000000000000000 T main +                          U puts +``` + +Use the `ldd` utility to list dynamic link libraries: + +``` +$ ldd hellogcc +linux-vdso.so.1 (0x00007ffe3bdd7000) +libc.so.6 => /lib64/libc.so.6 (0x00007f223395e000) +/lib64/ld-linux-x86-64.so.2 (0x00007f2233b7e000) +``` + +### Wrap up + +In this article, you learned the various intermediate steps in GCC compilation and the utilities to examine the file type, symbol table, and libraries linked with an executable. The next time you use GCC, you'll understand the steps it takes to produce a binary file for you, and when something goes wrong, you know how to step through the process to resolve problems. + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/22/5/gnu-c-compiler + +作者:[Jayashree Huttanagoudar][a] +选题:[lkxed][b] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/jayashree-huttanagoudar +[b]: https://github.com/lkxed +[1]: https://opensource.com/sites/default/files/lead-images/build_structure_tech_program_code_construction.png +[2]: https://opensource.com/sites/default/files/2022-05/compiler-flowchart.png From 7089228224e5b52eefa7bdfbb7e74711890f0ac7 Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 20:02:54 +0800 Subject: [PATCH 004/223] =?UTF-8?q?[=E6=89=8B=E5=8A=A8=E9=80=89=E9=A2=98][?= =?UTF-8?q?tech]:=2020220520=20How=20to=20rename=20a=20branch,=20delete=20?= =?UTF-8?q?a=20branch,=20and=20find=20the=20author=20of=20a=20branch=20in?= =?UTF-8?q?=20Git.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... and find the author of a branch in Git.md | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md diff --git a/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md b/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md new file mode 100644 index 0000000000..bcb411371d --- /dev/null +++ b/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md @@ -0,0 +1,203 @@ +[#]: subject: "How to rename a branch, delete a branch, and find the author of a branch in Git" +[#]: via: "https://opensource.com/article/22/5/git-branch-rename-delete-find-author" +[#]: author: "Agil Antony https://opensource.com/users/agantony" +[#]: collector: "lkxed" +[#]: translator: " " +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +How to rename a branch, delete a branch, and find the author of a branch in Git +====== +Become an expert at the most common Git tasks for managing local and remote branches. + +![tree branches][1] +Image by [Erik Fitzpatrick][2], [CC BY-SA 4.0][3] + +One of Git's primary strengths is its ability to "fork" work into different branches. + +If you're the only person using a repository, the benefits are modest, but once you start working with many other contributors, branching is essential. Git's branching mechanism allows multiple people to work on a project, and even on the same file, at the same time. Users can introduce different features, independent of one another, and then merge the changes back to a main branch later. A branch created specifically for one purpose, such as adding a new feature or fixing a known bug, is sometimes called a topic branch. + +Once you start working with branches, it's helpful to know how to manage them. Here are the most common tasks developers do with Git branches in the real world. + +### Rename a branch using Git + +Renaming a topic branch is useful if you have named a branch incorrectly or you want to use the same branch to switch between different bugs or tasks after merging the content into the main branch. + +#### Rename a local branch + +1. Rename the local branch: + +``` +$ git branch -m +``` + +Of course, this only renames your copy of the branch. If the branch exists on the remote Git server, continue to the next steps. + +2. Push the new branch to create a new remote branch: + +``` +$ git push origin +``` + +3. Delete the old remote branch: + +``` +$ git push origin -d -f +``` + +#### Rename the current branch + +When the branch you want to rename is your current branch, you don't need to specify the existing branch name. + +1. Rename the current branch: + +``` +$ git branch -m +``` + +2. Push the new branch to create a new remote branch: + +``` +$ git push origin +``` + +3. Delete the old remote branch: + +``` +$ git push origin -d -f +``` + +### Delete local and remote branches using Git + +As part of good repository hygiene, it's often recommended that you delete a branch after ensuring you have merged the content into the main branch. + +#### Delete a local branch + +Deleting a local branch only deletes the copy of that branch that exists on your system. If the branch has already been pushed to the remote repository, it remains available to everyone working with the repo. + +1. Checkout the central branch of your repository (such as main or master): + +``` +$ git checkout +``` + +2. List all the branches (local as well as remote): + +``` +$ git branch -a +``` + +3. Delete the local branch: + +``` +$ git branch -d +``` + +To remove all your local topic branches and retain only the *main* branch: + +``` +$ git branch | grep -v main | xargs git branch -d +``` + +#### Delete a remote branch + +Deleting a remote branch only deletes the copy of that branch that exists on the remote server. Should you decide that you didn't want to delete the branch after all, you can re-push it to the remote, such as GitHub, as long as you still have your local copy. + +1. Checkout the central branch of your repository (usually main or master): + +``` +$ git checkout +``` + +2. List all branches (local as well as remote): + +``` +$ git branch -a +``` + +3. Delete the remote branch: + +``` +$ git push origin -d +``` + +### Find the author of a remote topic branch using Git + +If you are the repository manager, you might need to do this so you can inform the author of an unused branch that it should be deleted. + +1. Checkout the central branch of your repository (such as main or master): + +``` +$ git checkout +``` + +2. Delete branch references to remote branches that do not exist: + +``` +$ git remote prune origin +``` + +3. List the author of all the remote topic branches in the repository, using the `--format` option along with special selectors (in this example, `%(authorname)` and `%(refname)` for author and branch name) to print just the information you want: + +``` +$ git for-each-ref --sort=authordate --format='%(authorname) %(refname)' refs/remotes +``` + +Example output: + +``` +tux  refs/remotes/origin/dev +agil refs/remotes/origin/main +``` + +You can add further formatting, including color coding and string manipulation, for easier readability: + +``` +$ git for-each-ref --sort=authordate \ +--format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)%(align:25,left)%(color:yellow) %(authorname)%(end)%(color:reset)%(refname:strip=3)' \ +refs/remotes +``` + +Example output: + +``` +01/16/2019 03:18 PM tux      dev +05/15/2022 10:35 PM agil     main +``` + +You can use grep to get the author of a specific remote topic branch: + +``` +$ git for-each-ref --sort=authordate \ +--format='%(authorname) %(refname)' \ +refs/remotes | grep +``` + +### Get good at branching + +There are nuances to how Git branching works depending on the point at which you want to fork the code base, how the repository maintainer manages branches, squashing, rebasing, and so on. Here are three articles for further reading on this topic: + +* [Explaining Git branches with a LEGO analogy][4], by Seth Kenlon +* [My guide to using the Git push command safely][5], by Noaa Barki +* [A guide to Git branching][6], by Kedar Vijay Kulkarni + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/22/5/git-branch-rename-delete-find-author + +作者:[Agil Antony][a] +选题:[lkxed][b] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/agantony +[b]: https://github.com/lkxed +[1]: https://opensource.com/sites/default/files/tree-branches.jpg +[2]: https://www.flickr.com/photos/22244945@N00/3353319002 +[3]: https://creativecommons.org/licenses/by-sa/4.0/ +[4]: https://opensource.com/article/22/4/git-branches +[5]: https://opensource.com/article/22/4/git-push +[6]: https://opensource.com/article/18/5/git-branching From d1310d52bb051b377e74929a9758d793532acf62 Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 20:04:03 +0800 Subject: [PATCH 005/223] =?UTF-8?q?[=E6=89=8B=E5=8A=A8=E9=80=89=E9=A2=98][?= =?UTF-8?q?tech]:=2020220520=20Ubuntu=20vs=20Manjaro-=20Comparing=20the=20?= =?UTF-8?q?Different=20Linux=20Experiences.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...mparing the Different Linux Experiences.md | 206 ++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 sources/tech/20220520 Ubuntu vs Manjaro- Comparing the Different Linux Experiences.md diff --git a/sources/tech/20220520 Ubuntu vs Manjaro- Comparing the Different Linux Experiences.md b/sources/tech/20220520 Ubuntu vs Manjaro- Comparing the Different Linux Experiences.md new file mode 100644 index 0000000000..caee2de033 --- /dev/null +++ b/sources/tech/20220520 Ubuntu vs Manjaro- Comparing the Different Linux Experiences.md @@ -0,0 +1,206 @@ +[#]: subject: "Ubuntu vs Manjaro: Comparing the Different Linux Experiences" +[#]: via: "https://itsfoss.com/ubuntu-vs-manjaro/" +[#]: author: "Ankush Das https://itsfoss.com/author/ankush/" +[#]: collector: "lkxed" +[#]: translator: " " +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +Ubuntu vs Manjaro: Comparing the Different Linux Experiences +====== +Ubuntu is the most popular Debian-based Linux distribution for desktops and servers. + +And Manjaro Linux is an Arch-based distro tailored for desktops. + +Both are entirely different when it comes to user experience and features. + +However, one of the common grounds is the [desktop environment][1] when considering Manjaro’s GNOME edition with Ubuntu. + +But, what exactly are the differences? Is the package manager on Manjaro better? Are software tools available on both Ubuntu and Manjaro? + +Here, we shall look at the differences in both the Linux distributions at certain key points. + +### Release Cycle + +Ubuntu offers two different release cycles, considering the version you pick. If you are going with the Long-Term Support version, you get security/maintenance updates for at least five years from its release. + +Suppose if you install Ubuntu 22.04 LTS, you will be getting updates until **April 2027**. + +![ubuntu22 04 lts about][2] + +The LTS version is what we recommend for most desktop users. + +However, if you want the latest and greatest, you can opt for the non-LTS releases that need an upgrade every **nine months**. Examples include Ubuntu 21.04, Ubuntu 21.10, and Ubuntu 22.10. + +Note that the non-LTS releases involve changes that may affect your workflow and user experience. So, it isn’t recommended for everyone. + +When choosing Manjaro Linux, you get a rolling release schedule for updates. So, you do not have to worry about the support for the version you use. It will automatically upgrade to the latest available version through regular updates. + +![manjaro about][3] + +With a rolling release cycle, you get the latest packages quickly. So, if you want to keep using an older version of the software, Manjaro Linux may not be the right choice for you. + +### Desktop Environments + +Ubuntu features a customized version of the GNOME desktop. It may not be the latest, but it is likely to include the latest GNOME desktop environment if you use a newer Ubuntu version. + +![ubuntu 22 04 wallpaper][4] + +There are no other desktop environments by Canonical (the company behind Ubuntu). + +However, if you want other desktop environments on top of Ubuntu, you can choose the official [Ubuntu flavours][5] including KDE, Budgie, LXQt, MATE, and XFCE as desktop environments. They are well-tested and stable Ubuntu Linux distributions when compared to unofficial or newer spins of Ubuntu with another desktop environment. + +However, Ubuntu flavours do not get five years of software support; instead, you will be limited to three years of support for LTS versions. + +With Manjaro, you can choose three official editions: XFCE, KDE, and GNOME. No matter the desktop environment, you stick to the rolling release model. + +![manjaro gnome 42][6] + +You do have some community editions with Budgie, MATE, LXQt, and more as well. + +### Package Manager or Software Ecosystem + +You shouldn’t have trouble finding most of the [essential Linux apps][7] on both the distros. + +However, Manjaro Linux gets an edge with a snappier experience using Pamac as its package manager. + +![manjaro package manager][8] + +Compared to the software center on Ubuntu, Manjaro Linux offers a better experience for quickly installing/updating the software. And, it also supports Flatpak/Snap out-of-the-box if you want to enable them with a single click. + +Ubuntu emphasizes Snap packages, and you will find some applications pre-installed as Snap (like Firefox web browser). + +![firefox as snap][9] + +In the case of Manjaro Linux, you get the freedom to enable Flatpak/Snap if required. + +With Ubuntu, the Software Center is not the best Linux offers. It could prove to be slower, as per your system configuration and over the year as you use it. + +![ubuntu 22 04 software center][10] + +In addition to that, Manjaro Linux has access to [AUR][11], which opens up access to almost every software that you may not find in Ubuntu’s software center. + +So, in terms of the software ecosystem and the package manager, Manjaro Linux does provide many advantages over Ubuntu. + +### Ease of Use and Targeted Users + +Ubuntu desktop is primarily tailored for ease of use. It focuses on providing the best possible combination of software and hardware compatibility to let any computer user work with Ubuntu Linux without needing to know most of the things in the Linux world. + +Even if someone doesn’t know what a “package manager” on Linux is, they can understand it perfectly fine as a unique replacement to Windows/macOS when they use it. + +Of course, we also have a guide to help you with [things to do after installing the latest Ubuntu version][12]. + +Manjaro Linux is also tailored for desktop usage. But, it isn’t primarily tailored for first-time Linux users. + +It aims to make the experience with Arch Linux easy. So, it mainly targets Linux users who want to use Arch Linux, but with some added convenience. + +### Stability + +![stability tux][13] + +Ubuntu LTS releases primarily focus on stability and reliability, so you can also use them on servers. + +Comparatively, Manjaro Linux may not be as stable out-of-the-box. You will have to choose the packages carefully to install in Manjaro Linux and keep an eye on your configurations to ensure that an update does not break your system experience. + +As for Ubuntu, you do not need to stress about the software updates, especially when considering the LTS version. The updates should not generally break your system. + +### Customization + +Ubuntu features a customized GNOME experience as set by Canonical for end-users. While you can choose to customize various aspects of your Linux distribution, Ubuntu offers little out of the box. + +Ubuntu has improved over the years, recently adding the ability to [add accent colors in Ubuntu 22.04 LTS][14]. But, it still has a long way to go. + +You will have to take the help of apps like [GNOME Tweak][15] to customize the desktop experience. + +When considering Manjaro’s GNOME edition, you will have to use the same tool to customize things yourself. + +Manjaro also performs a few customization tweaks to the look. But, it gives more control to change the layout and few other options. + +![manjaro layout][16] + +In terms of customization, you should be able to do the same thing on both Manjaro and Ubuntu. + +If you want more customization options, Manjaro Linux can be a good pick. And, if you want a customized experience without a lot of control over it, Ubuntu should be good enough. + +### Bloatware + +This may not be a big deal for everyone. But, if you dislike having many pre-installed applications, Ubuntu can be an annoyance. + +![ubuntu 22 apps][17] + +You can always remove the applications you do not want. However, you will find more applications and services installed with Ubuntu out of the box. + +With Manjaro, you also get to see the minimal essentials installed. But, they stick to the most essential utilities, minimizing the number of packages pre-installed. So, Manjaro gets an edge with less bloatware. + +However, there are chances that you may not find your favorite Linux app installed on Manjaro by default. So, if you like access to some of your favorite apps right after installation, Ubuntu can be a good choice. + +### Performance + +![ubuntu 22 04 neofetch lolcat][18] + +While Ubuntu has improved its performance and even works on a Raspberry Pi 2 GB variant, it is still not the best-performing Linux distribution. + +Of course, the performance does depend on the desktop environment you choose to use. + +However, compared to Manjaro’s GNOME edition, Manjaro provides a snappier experience. + +Note that your user experience with the performance and animation preferences also depends on your system configuration. For instance, the recommended system requirements (1 GB RAM + 1 GHz processor) for Manjaro give you room to use older computers. + +But, with Ubuntu, at the time of writing, you need at least 4 GB RAM and a 2 GHz dual-core processor to get an ideal desktop experience. + +### Documentation + +Ubuntu is easier to use and potentially more comfortable for new users, considering its popularity. + +[Ubuntu’s documentation][19] is good enough, if not excellent. + +When it comes to Manjaro Linux, they have a [wiki][20] with essential information and in-depth guides to help you out. + +In general, the [documentation available for Arch Linux][21] is meticulous, and almost everyone (even the veterans) refers to it to get help. + +The documentation for Arch Linux also applies to Manjaro Linux in a big way, so you do get an advantage in terms of documentation with Manjaro Linux over Ubuntu. + +### Wrapping Up + +Being two entirely different Linux distributions, they serve various kinds of users. You can choose to use anything if you want to explore the operating system and see if it suits you. + +However, if you want to avoid making any changes to your system and want to focus on your work, irrespective of the Linux distro, Ubuntu should be a no-brainer. + +In any case, if the performance with Ubuntu affects your experience by a considerable margin, you should try Manjaro. You can read my [initial thoughts on switching to Manjaro from Ubuntu][22]. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/ubuntu-vs-manjaro/ + +作者:[Ankush Das][a] +选题:[lkxed][b] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/ankush/ +[b]: https://github.com/lkxed +[1]: https://itsfoss.com/what-is-desktop-environment/ +[2]: https://itsfoss.com/wp-content/uploads/2022/05/ubuntu22-04-lts-about.png +[3]: https://itsfoss.com/wp-content/uploads/2022/05/manjaro-about.png +[4]: https://itsfoss.com/wp-content/uploads/2022/04/ubuntu-22-04-wallpaper.jpg +[5]: https://itsfoss.com/which-ubuntu-install/ +[6]: https://itsfoss.com/wp-content/uploads/2022/05/manjaro-gnome-42.png +[7]: https://itsfoss.com/essential-linux-applications/ +[8]: https://itsfoss.com/wp-content/uploads/2022/05/manjaro-package-manager.png +[9]: https://itsfoss.com/wp-content/uploads/2022/04/firefox-as-snap.jpg +[10]: https://itsfoss.com/wp-content/uploads/2022/04/ubuntu-22-04-software-center.jpg +[11]: https://itsfoss.com/aur-arch-linux/ +[12]: https://itsfoss.com/things-to-do-after-installing-ubuntu-22-04/ +[13]: https://itsfoss.com/wp-content/uploads/2022/05/stability-tux.png +[14]: https://itsfoss.com/accent-color-ubuntu/ +[15]: https://itsfoss.com/gnome-tweak-tool/ +[16]: https://itsfoss.com/wp-content/uploads/2022/05/manjaro-layout.png +[17]: https://itsfoss.com/wp-content/uploads/2022/05/ubuntu-22-apps.jpg +[18]: https://itsfoss.com/wp-content/uploads/2022/04/ubuntu-22-04-neofetch-lolcat-800x445.png +[19]: https://help.ubuntu.com/ +[20]: https://wiki.manjaro.org/index.php/Main_Page +[21]: https://wiki.archlinux.org/ +[22]: https://news.itsfoss.com/manjaro-linux-experience/ From b3cb22e3f060e488238adeaa38730b36712dbe5d Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 20:27:31 +0800 Subject: [PATCH 006/223] =?UTF-8?q?[=E7=94=B3=E9=A2=86=E5=8E=9F=E6=96=87][?= =?UTF-8?q?tech]:=2020220520=20How=20to=20rename=20a=20branch,=20delete=20?= =?UTF-8?q?a=20branch,=20and=20find=20the=20author=20of=20a=20branch=20in?= =?UTF-8?q?=20Git.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..., delete a branch, and find the author of a branch in Git.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md b/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md index bcb411371d..cdec4751e4 100644 --- a/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md +++ b/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md @@ -2,7 +2,7 @@ [#]: via: "https://opensource.com/article/22/5/git-branch-rename-delete-find-author" [#]: author: "Agil Antony https://opensource.com/users/agantony" [#]: collector: "lkxed" -[#]: translator: " " +[#]: translator: "lkxed" [#]: reviewer: " " [#]: publisher: " " [#]: url: " " From e6cc6488f03f3f98b19975b6a5e3f34f59cbfdca Mon Sep 17 00:00:00 2001 From: lkxed Date: Fri, 20 May 2022 21:09:32 +0800 Subject: [PATCH 007/223] =?UTF-8?q?[=E6=8F=90=E4=BA=A4=E8=AF=91=E6=96=87][?= =?UTF-8?q?tech]:=2020220520=20How=20to=20rename=20a=20branch,=20delete=20?= =?UTF-8?q?a=20branch,=20and=20find=20the=20author=20of=20a=20branch=20in?= =?UTF-8?q?=20Git.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... and find the author of a branch in Git.md | 203 ----------------- ... and find the author of a branch in Git.md | 204 ++++++++++++++++++ 2 files changed, 204 insertions(+), 203 deletions(-) delete mode 100644 sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md create mode 100644 translated/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md diff --git a/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md b/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md deleted file mode 100644 index cdec4751e4..0000000000 --- a/sources/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md +++ /dev/null @@ -1,203 +0,0 @@ -[#]: subject: "How to rename a branch, delete a branch, and find the author of a branch in Git" -[#]: via: "https://opensource.com/article/22/5/git-branch-rename-delete-find-author" -[#]: author: "Agil Antony https://opensource.com/users/agantony" -[#]: collector: "lkxed" -[#]: translator: "lkxed" -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " - -How to rename a branch, delete a branch, and find the author of a branch in Git -====== -Become an expert at the most common Git tasks for managing local and remote branches. - -![tree branches][1] -Image by [Erik Fitzpatrick][2], [CC BY-SA 4.0][3] - -One of Git's primary strengths is its ability to "fork" work into different branches. - -If you're the only person using a repository, the benefits are modest, but once you start working with many other contributors, branching is essential. Git's branching mechanism allows multiple people to work on a project, and even on the same file, at the same time. Users can introduce different features, independent of one another, and then merge the changes back to a main branch later. A branch created specifically for one purpose, such as adding a new feature or fixing a known bug, is sometimes called a topic branch. - -Once you start working with branches, it's helpful to know how to manage them. Here are the most common tasks developers do with Git branches in the real world. - -### Rename a branch using Git - -Renaming a topic branch is useful if you have named a branch incorrectly or you want to use the same branch to switch between different bugs or tasks after merging the content into the main branch. - -#### Rename a local branch - -1. Rename the local branch: - -``` -$ git branch -m -``` - -Of course, this only renames your copy of the branch. If the branch exists on the remote Git server, continue to the next steps. - -2. Push the new branch to create a new remote branch: - -``` -$ git push origin -``` - -3. Delete the old remote branch: - -``` -$ git push origin -d -f -``` - -#### Rename the current branch - -When the branch you want to rename is your current branch, you don't need to specify the existing branch name. - -1. Rename the current branch: - -``` -$ git branch -m -``` - -2. Push the new branch to create a new remote branch: - -``` -$ git push origin -``` - -3. Delete the old remote branch: - -``` -$ git push origin -d -f -``` - -### Delete local and remote branches using Git - -As part of good repository hygiene, it's often recommended that you delete a branch after ensuring you have merged the content into the main branch. - -#### Delete a local branch - -Deleting a local branch only deletes the copy of that branch that exists on your system. If the branch has already been pushed to the remote repository, it remains available to everyone working with the repo. - -1. Checkout the central branch of your repository (such as main or master): - -``` -$ git checkout -``` - -2. List all the branches (local as well as remote): - -``` -$ git branch -a -``` - -3. Delete the local branch: - -``` -$ git branch -d -``` - -To remove all your local topic branches and retain only the *main* branch: - -``` -$ git branch | grep -v main | xargs git branch -d -``` - -#### Delete a remote branch - -Deleting a remote branch only deletes the copy of that branch that exists on the remote server. Should you decide that you didn't want to delete the branch after all, you can re-push it to the remote, such as GitHub, as long as you still have your local copy. - -1. Checkout the central branch of your repository (usually main or master): - -``` -$ git checkout -``` - -2. List all branches (local as well as remote): - -``` -$ git branch -a -``` - -3. Delete the remote branch: - -``` -$ git push origin -d -``` - -### Find the author of a remote topic branch using Git - -If you are the repository manager, you might need to do this so you can inform the author of an unused branch that it should be deleted. - -1. Checkout the central branch of your repository (such as main or master): - -``` -$ git checkout -``` - -2. Delete branch references to remote branches that do not exist: - -``` -$ git remote prune origin -``` - -3. List the author of all the remote topic branches in the repository, using the `--format` option along with special selectors (in this example, `%(authorname)` and `%(refname)` for author and branch name) to print just the information you want: - -``` -$ git for-each-ref --sort=authordate --format='%(authorname) %(refname)' refs/remotes -``` - -Example output: - -``` -tux  refs/remotes/origin/dev -agil refs/remotes/origin/main -``` - -You can add further formatting, including color coding and string manipulation, for easier readability: - -``` -$ git for-each-ref --sort=authordate \ ---format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)%(align:25,left)%(color:yellow) %(authorname)%(end)%(color:reset)%(refname:strip=3)' \ -refs/remotes -``` - -Example output: - -``` -01/16/2019 03:18 PM tux      dev -05/15/2022 10:35 PM agil     main -``` - -You can use grep to get the author of a specific remote topic branch: - -``` -$ git for-each-ref --sort=authordate \ ---format='%(authorname) %(refname)' \ -refs/remotes | grep -``` - -### Get good at branching - -There are nuances to how Git branching works depending on the point at which you want to fork the code base, how the repository maintainer manages branches, squashing, rebasing, and so on. Here are three articles for further reading on this topic: - -* [Explaining Git branches with a LEGO analogy][4], by Seth Kenlon -* [My guide to using the Git push command safely][5], by Noaa Barki -* [A guide to Git branching][6], by Kedar Vijay Kulkarni - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/22/5/git-branch-rename-delete-find-author - -作者:[Agil Antony][a] -选题:[lkxed][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/agantony -[b]: https://github.com/lkxed -[1]: https://opensource.com/sites/default/files/tree-branches.jpg -[2]: https://www.flickr.com/photos/22244945@N00/3353319002 -[3]: https://creativecommons.org/licenses/by-sa/4.0/ -[4]: https://opensource.com/article/22/4/git-branches -[5]: https://opensource.com/article/22/4/git-push -[6]: https://opensource.com/article/18/5/git-branching diff --git a/translated/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md b/translated/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md new file mode 100644 index 0000000000..fa61c86268 --- /dev/null +++ b/translated/tech/20220520 How to rename a branch, delete a branch, and find the author of a branch in Git.md @@ -0,0 +1,204 @@ +[#]: subject: "How to rename a branch, delete a branch, and find the author of a branch in Git" +[#]: via: "https://opensource.com/article/22/5/git-branch-rename-delete-find-author" +[#]: author: "Agil Antony https://opensource.com/users/agantony" +[#]: collector: "lkxed" +[#]: translator: "lkxed" +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +Git 教程:重命名分支、删除分支、查看分支作者 +====== +掌握管理本地/远程分支等最常见的 Git 任务。 + +![树枝][1] + +图源:[Erik Fitzpatrick][2],[CC BY-SA 4.0][3] + +Git 的主要优势之一就是它能够将工作“分叉”到不同的分支中。 + +如果只有你一个人在使用某个存储库,分支的好处是有限的。但是,一旦你开始与许多其他贡献者一起工作,分支就变得必不可少。Git 的分支机制允许多人同时处理一个项目,甚至是同一个文件。用户可以引入不同的功能,彼此独立,然后稍后将更改合并回主分支。那些专门为一个目的创建的分支,有时也被称为主题分支,例如添加新功能或修复已知错误。 + +当你开始使用分支,了解如何管理它们会很有帮助。以下是开发者在现实世界中使用 Git 分支执行的最常见任务。 + +### 重命名分支 + +有时候,你或许会错误地命名了一个分支,或者你会想要在内容合并到主分支后,使用同一个分支在不同的错误或任务之间切换。在这种情况下,重命名主题分支就会很有帮助。 + +#### 重命名本地分支 + +1. 重命名本地分支: + +``` +$ git branch -m +``` + +当然,这只会重命名您的分支副本。如果远程 Git 服务器上存在该分支,请继续执行后续步骤。 + +2. 推送这个新分支,从而创建一个新的远程分支: + +``` +$ git push origin +``` + +3. 删除旧的远程分支: + +``` +$ git push origin -d -f +``` + +#### 重命名当前分支 + +当你要重命名的分支恰好是当前分支时,你不需要指定旧的分支名称。 + +1. 重命名当前分支: + +``` +$ git branch -m +``` + +2. 推送新分支,从而创建一个新的远程分支: + +``` +$ git push origin +``` + +3. 删除旧的远程分支: + +``` +$ git push origin -d -f +``` + +### 使用 Git 删除本地和远程分支 + +为了保持存储库的整洁,通常建议你在确保已将内容合并到主分支后,删除临时分支。 + +#### 删除本地分支 + +删除本地分支只会删除系统上存在的该分支的副本。如果分支已经被推送到远程存储库,它仍然可供使用该存储库的每个人使用。 + +1. 签出存储库的主分支(例如 `main` 或 `master`): + +``` +$ git checkout +``` + +2. 列出所有分支(本地和远程): + +``` +$ git branch -a +``` + +3. 删除本地分支: + +``` +$ git branch -d +``` + +要删除所有本地主题分支并仅保留 `main` 分支: + +``` +$ git branch | grep -v main | xargs git branch -d +``` + +#### 删除远程分支 + +删除远程分支只会删除远程服务器上存在的该分支的副本。如果你想撤销删除,也可以将其重新推送到远程(例如 GitHub),只要你还有本地副本即可。 + +1. 签出存储库的主分支(通常是 `main` 或 `master`): + +``` +$ git checkout +``` + +2. 列出所有分支(本地和远程): + +``` +$ git branch -a +``` + +3. 删除远程分支: + +``` +$ git push origin -d +``` + +### 查看远程主题分支的作者 + +如果你是存储库管理员,你可能会有这个需求,以便通知未使用分支的作者它将被删除。 + +1. 签出存储库的主分支(例如 `main` 或 `master`): + +``` +$ git checkout +``` + +2. 删除不存在的远程分支的分支引用: + +``` +$ git remote prune origin +``` + +3. 列出存储库中所有远程主题分支的作者,使用 `--format` 选项,并配合特殊的选择器来只打印你想要的信息(在本例中,`%(authorname)` 和 `%(refname)` 分别代表作者名字和分支名称): + +``` +$ git for-each-ref --sort=authordate --format='%(authorname) %(refname)' refs/remotes +``` + +示例输出: + +``` +tux  refs/remotes/origin/dev +agil refs/remotes/origin/main +``` + +你可以添加更多格式,包括颜色编码和字符串操作,以便于阅读: + +``` +$ git for-each-ref --sort=authordate \ +--format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)%(align:25,left)%(color:yellow) %(authorname)%(end)%(color:reset)%(refname:strip=3)' \ +refs/remotes +``` + +示例输出: + +``` +01/16/2019 03:18 PM tux      dev +05/15/2022 10:35 PM agil     main +``` + +你可以使用 `grep` 获取特定远程主题分支的作者: + +``` +$ git for-each-ref --sort=authordate \ +--format='%(authorname) %(refname)' \ +refs/remotes | grep +``` + +### 熟练运用分支 + +Git 分支的工作方式存在细微差别,具体取决于你想要分叉代码库的位置、存储库维护者如何管理分支、压缩squashing变基rebasing等。若想进一步了解该主题,你可以阅读下面这三篇文章: + +* [《用乐高来类比解释 Git 分支》][4],作者:Seth Kenlon +* [《我的 Git push 命令的安全使用指南》][5],作者:Noaa Barki +* [《Git 分支指南》][6],作者:Kedar Vijay Kulkarni + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/22/5/git-branch-rename-delete-find-author + +作者:[Agil Antony][a] +选题:[lkxed][b] +译者:[lkxed](https://github.com/lkxed) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/agantony +[b]: https://github.com/lkxed +[1]: https://opensource.com/sites/default/files/tree-branches.jpg +[2]: https://www.flickr.com/photos/22244945@N00/3353319002 +[3]: https://creativecommons.org/licenses/by-sa/4.0/ +[4]: https://opensource.com/article/22/4/git-branches +[5]: https://opensource.com/article/22/4/git-push +[6]: https://opensource.com/article/18/5/git-branching From d14b263a82897d6a9a54572454e65d04123d5edf Mon Sep 17 00:00:00 2001 From: f Date: Fri, 20 May 2022 21:58:38 +0800 Subject: [PATCH 008/223] Update 20210207 3 ways to play video games on Linux.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 翻译申请 --- sources/tech/20210207 3 ways to play video games on Linux.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/tech/20210207 3 ways to play video games on Linux.md b/sources/tech/20210207 3 ways to play video games on Linux.md index 1c132ab588..e01c4b2e77 100644 --- a/sources/tech/20210207 3 ways to play video games on Linux.md +++ b/sources/tech/20210207 3 ways to play video games on Linux.md @@ -1,5 +1,5 @@ [#]: collector: (lujun9972) -[#]: translator: ( ) +[#]: translator: (godgithubf) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) From a30c8fc3bee2907721b747277288c90a0a1b374c Mon Sep 17 00:00:00 2001 From: CoWave Fall <105500745+CoWave-Fall@users.noreply.github.com> Date: Fri, 20 May 2022 22:13:51 +0800 Subject: [PATCH 009/223] Update and rename sources/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md to translated/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md --- ...r UI for Raspberry Pi with XML and Java.md | 282 ----------------- ...r UI for Raspberry Pi with XML and Java.md | 287 ++++++++++++++++++ 2 files changed, 287 insertions(+), 282 deletions(-) delete mode 100644 sources/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md create mode 100644 translated/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md diff --git a/sources/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md b/sources/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md deleted file mode 100644 index f66500b30d..0000000000 --- a/sources/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md +++ /dev/null @@ -1,282 +0,0 @@ -[#]: subject: (Build a printer UI for Raspberry Pi with XML and Java) -[#]: via: (https://opensource.com/article/21/3/raspberry-pi-totalcross) -[#]: author: (Edson Holanda Teixeira Junior https://opensource.com/users/edsonhtj) -[#]: collector: (lujun9972) -[#]: translator: (CoWave-Fall) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) - -Build a printer UI for Raspberry Pi with XML and Java -====== -TotalCross makes it quick to build user interfaces for embedded -applications. -![Tips and gears turning][1] - -Creating a GUI from scratch is a very time consuming process, dealing with all the positions and alignments in hard code can be really tough for some programmers. In this article, I demonstrate how to speed up this process using XML. - -This project uses [TotalCross][2] as the target framework. TotalCross is an open source, cross-platform software development kit (SDK) developed to create GUIs for embedded devices faster. TotalCross provides Java's development benefits without needing to run Java on a device because it uses its own bytecode and virtual machine (TC bytecode and TCVM) for performance enhancement. - -I also use Knowcode-XML, an open source XML parser for the TotalCross framework, which converts XML files into TotalCross components. - -### Project requirements - -To reproduce this project, you need: - - * [KnowCode-XML][3] - * [VSCode][4] [or VSCodium][5] - * [An Android development environment][6] - * [TotalCross plugin for VSCode][7] - * Java 11 or greater for your development platform ([Linux][8], [Mac][9], or [Windows][10]) - * [Git][11] - - - -### Building the embedded application - -This application consists of an embedded GUI with basic print functionalities, such as scan, print, and copy. - -![printer init screen][12] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -Several steps are required to create this GUI, including generating the GUI with Android-XML and then using the Knowcode-XML parser to run it on the TotalCross Framework. - -#### 1\. Generate the Android XML - -For creating the XML file, first create a simple Android screen, and then customize it. If you don't know how to write Android-XM, or you just want a headstart, you can download this application’s XML from this [GitHub project][14]. This project also contains the images you need to render the GUI. - -#### 2\. Adjust the XML - -After generating the XML files, you need to make some fine adjustments to make sure everything is aligned, with the right proportions, and has the correct path to the images. - -Add the XML layouts to the **Layouts** folder and all the assets to the **Drawable** folder. Then you can start to customize the XML. - -For example, if you want to change an XML object's background, change the `android:background` attribute: - - -``` -`android:background="@drawable/scan"` -``` - -You can change the object's position with `tools:layout_editor_absoluteX` and `tools:layout_editor_absoluteY`: - - -``` -tools:layout_editor_absoluteX="830dp" -tools:layout_editor_absoluteY="511dp" -``` - -Change the object's size with `android:layout_width` and `android:layout_height`: - - -``` -android:layout_width="70dp" -android:layout_height="70dp" -``` - -If you want to put text on an object, you can use `android:textSize`, `android:text`, `android:textStyle`, and `android:textColor`: - - -``` -android:textStyle="bold" -android:textColor="#000000" -android:textSize="20dp" -android:text="2:45PM" -``` - -Here is an example of a complete XML object: - - -``` -    <ImageButton -           android:id="@+id/ImageButton" -           android:layout_width="70dp" -           android:layout_height="70dp" -           tools:layout_editor_absoluteX="830dp" -           tools:layout_editor_absoluteY="511dp" -           android:background="@drawable/home_config" /> -``` - -#### 3\. Run the GUI on TotalCross - -After you make all the XML adjustments, it's time to run it on TotalCross. Create a new project on the TotalCross extension and add the **XML** and **Drawable** folders to the **Main** folder. If you're not sure how to create a TotalCross project, see our [get started guide][15]. - -After configuring the environment, use `totalcross.knowcode.parse.XmlContainerFactory` and `import totalcross.knowcode.parse.XmlContainerLayout` to use the XML GUI on the TotalCross framework. You can find more information about using KnowCode-XML on its [GitHub page][3]. - -#### 4\. Add transitions - -This project's smooth transition effect is created by the `SlidingNavigator` class, which uses TotalCross' `ControlAnimation` class to slide from one screen to the other. - -Call `SlidingNavigator` on the `XMLpresenter` class: - - -``` -`new SlidingNavigator(this).present(HomePresenter.class);` -``` - -Implement the `present` function on the `SlidingNavigator` class: - - -``` -public void present(Class<? extends XMLPresenter> presenterClass) -         throws [InstantiationException][16], [IllegalAccessException][17] { -      final XMLPresenter presenter = cache.containsKey(presenterClass) ? cache.get(presenterClass) -            : presenterClass.newInstance(); -      if (!cache.containsKey(presenterClass)) { -         cache.put(presenterClass, presenter); -      } - -      if (presenters.isEmpty()) { -         window.add(presenter.content, LEFT, TOP, FILL, FILL); -      } else { -         XMLPresenter previous = presenters.lastElement(); - -         window.add(presenter.content, AFTER, TOP, SCREENSIZE, SCREENSIZE, previous.content); -``` - -`PathAnimation` in animation control creates the sliding animation from one screen to another: - - -``` -         PathAnimation.create(previous.content, -Settings.screenWidth, 0, new ControlAnimation.AnimationFinished() { -            @Override -            public void onAnimationFinished(ControlAnimation anim) { -               window.remove(previous.content); -            } -         }, 1000).with(PathAnimation.create(presenter.content, 0, 0, new ControlAnimation.AnimationFinished() { -            @Override -            public void onAnimation Finished(Control Animation anim) { -               presenter.content.setRect(LEFT, TOP, FILL, FILL); -            } -         }, 1000)).start(); -      } -      presenter.setNavigator(this); -      presenters.push(presenter); -      presenter.bind2(); -      if (presenter.isFirstPresent) { -         presenter.onPresent(); -         presenter.isFirstPresent = false; -      } -``` - -#### 5\. Load spinners - -Another nice feature in the printer application is the loading screen animation that shows progress. It includes text and a spinning animation. - -![Loading Spinner][18] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -Implement this feature by adding a timer and a timer listener to update the progress label, then call the function `spinner.start()`. All of the animations are auto-generated by TotalCross and KnowCode: - - -``` -public void startSpinner() { -        time = content.addTimer(500); -        content.addTimerListener((e) -> { -            try { -                progress(); // Updates the Label -            } catch (InstantiationException | IllegalAccessException e1) { -                // TODO Auto-generated catch block -                e1.printStackTrace(); -            } -        }); -        Spinner spinner = (Spinner) ((XmlContainerLayout) content).getControlByID("@+id/spinner"); -        spinner.start(); -    } -``` - -The spinner is instantiated as a reference to the `XmlContainerLayout` spinner described in the XML file: - - -``` -<ProgressBar -android:id="@+id/spinner" -android:layout_width="362dp" -android:layout_height="358dp" -tools:layout_editor_absoluteX="296dp" -tools:layout_editor_absoluteY="198dp" -   android:indeterminateTint="#2B05C7" -style="?android:attr/progressBarStyle" /> -``` - -#### 6\. Build the application - -It's time to build the application. You can see and change the target systems in `pom.xml`. Make sure the **Linux Arm** target is available. - -If you are using VSCode, press **F1** on the keyboard, select **TotalCross: Package** and wait for the package to finish. Then you can see the installation files in the **Target** folder. - -#### 7\. Deploy and run the application on Raspberry Pi - -To deploy the application on a [Raspberry Pi 4][19] with the SSH protocol, press **F1** on the keyboard. Select **TotalCross: Deploy&Run** and provide information about your SSH connection: User, IP, Password, and Application Path. - -![TotalCross: Deploy&Run][20] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -![SSH user][21] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -![IP address][22] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -![Password][23] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -![Path][24] - -(Edson Holanda Teixeira Jr, [CC BY-SA 4.0][13]) - -Here's what the application looks like running on the machine. - -### What's next? - -KnowCode makes it easier to create and manage your application screens using Java. Knowcode-XML translates your XML into a TotalCross GUI that in turn generates the binary to run on your Raspberry Pi. - -Combining KnowCode technology with TotalCross enables you to create embedded applications faster. Find out what else you can do by accessing our [embedded samples][25] on GitHub and editing your own application. - -If you have questions, need help, or just want to interact with other embedded GUI developers, feel free to join our [Telegram][26] group to discuss embedded applications on any framework. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/21/3/raspberry-pi-totalcross - -作者:[Edson Holanda Teixeira Junior][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/edsonhtj -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/gears_devops_learn_troubleshooting_lightbulb_tips_520.png?itok=HcN38NOk (Tips and gears turning) -[2]: https://opensource.com/article/20/7/totalcross-cross-platform-development -[3]: https://github.com/TotalCross/knowcode-xml -[4]: https://code.visualstudio.com/ -[5]: https://opensource.com/article/20/6/open-source-alternatives-vs-code -[6]: https://developer.android.com/studio -[7]: https://marketplace.visualstudio.com/items?itemName=totalcross.vscode-totalcross -[8]: https://opensource.com/article/19/11/install-java-linux -[9]: https://opensource.com/article/20/7/install-java-mac -[10]: http://adoptopenjdk.net -[11]: https://opensource.com/life/16/7/stumbling-git -[12]: https://opensource.com/sites/default/files/uploads/01_printergui.png (printer init screen) -[13]: https://creativecommons.org/licenses/by-sa/4.0/ -[14]: https://github.com/TotalCross/embedded-samples/tree/main/printer-application/src/main/resources/layout -[15]: https://totalcross.com/get-started/?utm_source=opensource&utm_medium=article&utm_campaign=printer -[16]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+instantiationexception -[17]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+illegalaccessexception -[18]: https://opensource.com/sites/default/files/uploads/03progressspinner.png (Loading Spinner) -[19]: https://www.raspberrypi.org/products/raspberry-pi-4-model-b/ -[20]: https://opensource.com/sites/default/files/uploads/04_totalcross-deployrun.png (TotalCross: Deploy&Run) -[21]: https://opensource.com/sites/default/files/uploads/05_ssh.png (SSH user) -[22]: https://opensource.com/sites/default/files/uploads/06_ip.png (IP address) -[23]: https://opensource.com/sites/default/files/uploads/07_password.png (Password) -[24]: https://opensource.com/sites/default/files/uploads/08_path.png (Path) -[25]: https://github.com/TotalCross/embedded-samples -[26]: https://t.me/totalcrosscommunity diff --git a/translated/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md b/translated/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md new file mode 100644 index 0000000000..828eb188b8 --- /dev/null +++ b/translated/tech/20210305 Build a printer UI for Raspberry Pi with XML and Java.md @@ -0,0 +1,287 @@ +[#]: subject: (Build a printer UI for Raspberry Pi with XML and Java) +[#]: via: (https://opensource.com/article/21/3/raspberry-pi-totalcross) +[#]: author: (Edson Holanda Teixeira Junior https://opensource.com/users/edsonhtj) +[#]: collector: (lujun9972) +[#]: translator: (CoWave-Fall) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) + +用 XML 和 Java 构建树莓派打印机的用户界面(UI) +====== +使用 TotalCross 来快速构建嵌入式系统程序的用户界面。 + +![Tips and gears turning][1] + +从头开始构建 GUI 是一个非常耗时的过程,处理代码中的位置和对齐对于一些程序员来说确实很困难。所以在本文中,我将演示如何使用 XML 加快这一过程。 + + +本项目使用 [TotalCross][2] 作为目标框架。 TotalCross 是一个开源的跨平台软件开发工具包 (SDK),旨在更快地为嵌入式设备创建 GUI。 TotalCross 无需在设备上运行 Java 即可提供 Java 的开发优势,因为它使用自己的字节码和虚拟机( TC 字节码TC bytecode 和 TCVM)来增强性能。 + +我还使用了 Knowcode-XML,这是一个用于 TotalCross 框架的开源 XML 解析器,它可以将 XML 文件转换为 TotalCross 组件。 + + +### 项目需求 + +要重现此项目,您需要: + + * [KnowCode-XML][3] + * [VSCode][4] [或 VSCodium][5] + * [一个 Android 开发环境][6] + * [用于 VSCode 的 TotalCross 插件][7] + * 适用于您的开发平台([Linux][8]、[Mac][9] 或 [Windows][10])的 Java,需要 Java 11(或更高版本) + * [Git][11] + + + +### 制作嵌入式应用程序 + +该应用程序包含一个具有基本打印功能的嵌入式 GUI,例如扫描、打印和复印。 + +![打印机初始化画面][12] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +构建这个 GUI 需要几个步骤,包括使用 Android-XML 生成 GUI,然后使用 Knowcode-XML 解析器在 TotalCross 框架上运行它。 + +#### 1\. 生成 Android XML + +要创建 XML 文件,首先构建一个简单的 Android 屏幕,然后对其进行自定义。 如果你不知道如何编写 Android-XM,或者你只是想简单尝试一下,你可以从这个 [GitHub 项目][14] 中下载这个应用程序的 XML。 该项目还包含渲染 GUI 要用到的图片。 + +#### 2\. 调整 XML + +生成 XML 文件后,您需要进行一些微调以确保所有内容都已经对齐、比例正确并且图像的路径正确。 + +将 XML 布局添加到 **Layouts** 文件夹,将所有资源添加到 **Drawable** 文件夹。然后您就可以开始自定义 XML 了。 + +例如,如果想要更改 XML 对象的背景,可以更改 `android:background` 属性: + + +``` +`android:background="@drawable/scan"` +``` + +您也可以使用 `tools:layout_editor_absoluteX` 和 `tools:layout_editor_absoluteY` 更改对象的位置: + + +``` +tools:layout_editor_absoluteX="830dp" +tools:layout_editor_absoluteY="511dp" +``` + +或者使用 `android:layout_width` 和 `android:layout_height` 更改对象的大小: + + +``` +android:layout_width="70dp" +android:layout_height="70dp" +``` + +如果要在对象上放置文本,可以使用 `android:textSize`、`android:text`、`android:textStyle` 和 `android:textColor`: + + +``` +android:textStyle="bold" +android:textColor="#000000" +android:textSize="20dp" +android:text="2:45PM" +``` + +下面是一个完整的 XML 对象的示例: + + +``` +    ; +``` + +#### 3\. 在 TotalCross 上运行 GUI + +完成所有 XML 调整后,就可以在 TotalCross 上运行它了。 在 TotalCross 扩展(译注:在 VSCode 里面)上创建一个新项目,并将 **XML** 和 **Drawable** 文件夹添加到 **Main** 文件夹里。 如果您仍然不确定如何创建 TotalCross 项目,请参阅我们的 [入门指南][15]。 + +配置好环境后,使用 `totalcross.knowcode.parse.XmlContainerFactory` 和 `import totalcross.knowcode.parse.XmlContainerLayout` 在 TotalCross 框架上使用 XML GUI。 您可以在其 [GitHub 页面][3] 上找到更多关于使用 KnowCode-XML 的信息。 + +#### 4\. 添加过渡效果 + +这个项目的平滑过渡效果是由 `SlidingNavigator` 类创建的,它使用TotalCross的 `ControlAnimation` 类从一个屏幕滑到另一个屏幕。 + +在 `XMLpresenter` 类上调用 `SlidingNavigator`: + + +``` +`new SlidingNavigator(this).present(HomePresenter.class);` +``` + +在 `SlidingNavigator` 类上实现 `present` 函数: + + +``` +public void present(Class<? extends XMLPresenter> presenterClass) +         throws [InstantiationException][16], [IllegalAccessException][17] { +      final XMLPresenter presenter = cache.containsKey(presenterClass) ? cache.get(presenterClass) +            : presenterClass.newInstance(); +      if (!cache.containsKey(presenterClass)) { +         cache.put(presenterClass, presenter); +      } + +      if (presenters.isEmpty()) { +         window.add(presenter.content, LEFT, TOP, FILL, FILL); +      } else { +         XMLPresenter previous = presenters.lastElement(); + +         window.add(presenter.content, AFTER, TOP, SCREENSIZE, SCREENSIZE, previous.content); +``` + +使用动画控件中的 `PathAnimation` 来创建从一个屏幕到另一个屏幕的滑动动画: + + +``` +         PathAnimation.create(previous.content, -Settings.screenWidth, 0, new ControlAnimation.AnimationFinished() { +            @Override +            public void onAnimationFinished(ControlAnimation anim) { +               window.remove(previous.content); +            } +         }, 1000).with(PathAnimation.create(presenter.content, 0, 0, new ControlAnimation.AnimationFinished() { +            @Override +            public void onAnimation Finished(Control Animation anim) { +               presenter.content.setRect(LEFT, TOP, FILL, FILL); +            } +         }, 1000)).start(); +      } +      presenter.setNavigator(this); +      presenters.push(presenter); +      presenter.bind2(); +      if (presenter.isFirstPresent) { +         presenter.onPresent(); +         presenter.isFirstPresent = false; +      } +``` + +#### 5\. 加载 环形进度条 spinner + +打印机应用程序的另一个不错的功能是显示进度的加载屏幕动画。它包括文本和旋转动画。 + +![加载环形进度条][18] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +通过添加定时器和定时器监听器来更新进度标签,然后调用函数 `spinner.start()` 来实现此功能。所有的动画都是由 TotalCross 和 KnowCode 自动生成的: + + +``` +public void startSpinner() { + time = content.addTimer(500); + content.addTimerListener((e) -> { + try { + progress(); // Updates the Label + } catch (InstantiationException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + }); + Spinner spinner = (Spinner) ((XmlContainerLayout) content).getControlByID("@+id/spinner"); + spinner.start(); + } +``` + +这里的环形进度条被实例化为对 XML 文件中描述的 `XmlContainerLayout` 环形进度条 spinner 的引用: + + +``` + +``` + +#### 6\. 构建应用程序 + +是时候构建应用程序了。 您可以在 `pom.xml` 中查看和更改目标系统target systems。 请确保 **Linux Arm** 目标可用。 + +如果您使用的是 VSCode,请按下键盘上的 **F1** 键,选择 **TotalCross: Package** 并等待完成。 然后就可以在 **Target** 文件夹中看到安装文件了。 + +#### 7\. 在树莓派上部署和运行应用程序 + +要使用 SSH 协议在 [树莓派][19] 上部署应用程序,请按键盘上的 **F1**。 选择 **TotalCross: Deploy&Run** 并提供有关您的 SSH 连接的信息,如:用户名、IP地址、密码和应用程序路径。 + +![TotalCross:部署与运行][20] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +![配置 SSH 用户名][21] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +![配置 IP 地址][22] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +![输入密码][23] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +![配置路径][24] + +(图片提供:Edson Holanda Teixeira Jr,遵循[CC BY-SA 4.0][13]协议) + +这是应用程序在机器上运行的样子。 + +